I’m working on an edit admin form and I’m populating two DropDownLists (hours and mins) from a DB. I need to extract the hours (12 hour format) and minutes from the returned DateTime object in the DB. Here’s what I’ve tried:
DateTime dt = DateTime.Parse(biz.GetStartDateByID(classID).ToString());
int hrs = Convert.ToDateTime(dt.ToString()).Hour;
For “2012-03-08 22:45:00.000” in the DB, this gives “22” for hours. What’s the best way of extracting the hours in 12 hour format and the minutes? For example, if the hours value in the DateTime object was “18”, I’d need it as “6”.
1 Answer