Hi, I am trying to create a sort of day planner with task a start_time and an end_time both entered as string using concatination of comboboxes(hour:minute:second AM/PM) and saved in a database as Datetime I try diferent conversion i found online but it doesn't work. Does anybody have an idea of how to approach Time conversion(only time conversion don't want use the date)

3 Years
Discussion Span
Last Post by __avd

Hello sydoggs, Welcome to daniweb!
What is the problem exactly? Are you trying to convert the data in order to put it into the database? There are multiple ways of converting data. One way to do this is to use Convert.ToDateTime. Let's say I have a label with a string. I can pass this into a variable converting it into datetime like so:

DateTime dateConversion = Convert.ToDateTime(lblTime.Text) //Conversion of a string into datetime.


I have a string time that I got from concatinating the value of 3 combobox the result is a string with the format hh:mm:ss tt and I want to convert it to Datetime to insert it in my database


You should save both date & time. However, use DateTime or Timespan to parse the string time.


        DateTime date = DateTime.Parse("10:10:10 AM");

        TimeSpan time = TimeSpan.Parse("20:10:10");

Or you can use TryParse / TryParseExact methods to parse the string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.