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)

Member Avatar

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

Have a look here.

commented: Merry christmas Danny +14

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.