How to convert time to datetime.
I am trying to send time to a datetime column.
So if I have 12:00 PM, how to convert to datetime , so i can send the value to the actual field in the database. I am trying to
insert the time values into the TimeFrom and TimeTo columns
Database columns,
ID, DateFrom, DateTo, TimeFrom, TimeTo
Loading

Anuja PawarRank #1,404 · 1.2K reputationPosted Dec 10, 2012, 3:02 AM EST
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Dec 10, 2012, 3:40 AM EST
TimeSpan ts = new TimeSpan(12);
DateTime dt = Convert.ToDateTime(ts.ToString());
Response.Write(dt);
It will give following output :
12/10/2012 12:00:00 PM
we can use dt variable for other operation ahead.
David SmithRank #999 · 2K reputationPosted Dec 10, 2012, 3:48 AM EST
from your logic below.
TimeSpan ts = new TimeSpan(12);
DateTime dt = Convert.ToDateTime(ts.ToString());
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Dec 10, 2012, 3:52 AM EST
TimeSpan ts = new TimeSpan(24);
DateTime dt = Convert.ToDateTime(ts.ToString());
Response.Write(dt);
12/10/2012 12:00:00 AM
David SmithRank #999 · 2K reputationPosted Dec 10, 2012, 4:24 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 10, 2012, 9:45 AM EST
Shebin babu4 reputationPosted Nov 27, 2018, 7:30 PM EST
var dateTime = DateTime.ParseExact(dateStr, "H:mm", null, System.Globalization.DateTimeStyles.None);
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 23, 2019, 6:36 AM EST