0

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)

4
Contributors
4
Replies
30
Views
2 Years
Discussion Span
Last Post by __avd
1

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.

0

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

0

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

Example:

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

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

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.