I have a data table, from Sage 100 ERP to be specific, that uses two separate columns to store the updated date and time (DateUpdated and TimeUpdated). I need to convert the data in these two fields to a DateTime object for comparisons. The dates look like "mm/dd/yyyy 12:00 AM" and the time is a decimal like 14.29297. So far I have been able to convert the time to the minute as follows:
private DateTime GetDateTime(string date, decimal time)
{
int hour = int.Parse(Math.Floor(time).ToString());
decimal minTemp = decimal.Parse((60 * (time - hour)).ToString());
int min = int.Parse(Math.Round(minTemp).ToString());
int sec = int.Parse(Math.Round(60 * (minTemp - min)).ToString());
string datetime = date + " " + hour.ToString() + ":" + min.ToString();
return DateTime.Parse(datetime);
}
I remove the 12:00AM from the date string before I pass it to this method. This works, but I'm loosing the seconds which is very important.
How can I convert the time to hours, minutes, and seconds?