Save Bootstrap TimePicker selected time to database in ASP.Net

Last Reply on Mar 28, 2015 01:27 AM By Mudassar

Posted on Mar 27, 2015 04:21 AM

This is the time picker which takes time in AM PM format for 1-12 hours. Now I am confused on how to convert this format to sql datetime format ...

I have used this :

var date = string.Format("{0:yyyy-MM-dd HH:mm tt}", DateTime.Parse("11:59 PM"));
ScriptManager.RegisterStartupScript(Page, GetType(), UniqueID, "ShowPopup('" + date + "');", true);

It works fine or hard coded value but when i do this :

string a = STBox.Value.Trim();
var date = string.Format("{0:yyyy-MM-dd HH:mm tt}", DateTime.Parse(a));
ScriptManager.RegisterStartupScript(Page, GetType(), UniqueID, "ShowPopup('" + date + "');", true);

It wont converts 12:00 AM selected in textbox while it converts other values.


Posted on Mar 28, 2015 01:27 AM

It database its 24 hour format so it will save 00:00 and while fetching you need to convert it back to 12 hour format.

There is no other solution to this