locked
TimeSpan from Bootstrap TimePicker ?? RRS feed

  • Question

  • User-1952516322 posted

    Hello,

    I have a bootstrap timePicker, what I want how can I change the value of time when I read it from database column dataType = time(7), and how can I get the value as Time to save it to database, I try these but I have an error ( String was not recognized as a valid TimeSpan ).

    TimeSpan time = TimeSpan.Parse(txtTime.Text); 

    I try these

    string time = txtTime.Text;   // if I enter 03:12 PM
    DateTime t = DateTime.ParseExact(time, "hh:mm tt", System.Globalization.CultureInfo.InvariantCulture);

    but the time saved in databae 03:12:00, not as I want >> 03:12 PM

    Wednesday, January 18, 2017 9:24 AM

All replies

  • User527778624 posted

    Hi,

    Time is saved as 24 hours format in database, if you want a custom time format use varchar.

    Check below C# code for saving correct time:

    DateTime t = DateTime.ParseExact("03:12 PM", "hh:mm tt", System.Globalization.CultureInfo.InvariantCulture);
    var timespan = t.TimeOfDay;

    Wednesday, January 18, 2017 2:42 PM