I have an hour field in a database like 1.4, 1.5, 1.7 that I need to convert back to HH:MM. What is the easiest way to do this?
I didn't mark this down, but this throws an InvalidCastException
Patrick McDonald
2009-07-06 15:55:48
+10
A:
double value;
TimeSpan t = TimeSpan.FromHours(value);
Example:
Console.WriteLine(TimeSpan.FromHours(1.4)); // prints 01:24:00 to the console.
Jason
2009-07-06 15:46:45
+1
A:
The HH (hour) figure is the number before the decimal.
To get the minutes figure, subtract the whole number portion so you only have the amount after the decimal, then multiply the fraction by 60 to get the minutes.
Bork Blatt
2009-07-06 15:48:42