Reputation: 161
I have an minutes field in a database like 138.34 that I need to convert back to HH:MM:SS What is the easiest way to do this?
Upvotes: 13
Views: 36977
Reputation: 460018
Use the TimeSpan
structure:
var timeSpan = TimeSpan.FromMinutes(138.34);
int hh = timeSpan.Hours;
int mm = timeSpan.Minutes;
int ss = timeSpan.Seconds;
Result:
Console.WriteLine("Hours:{0} Minutes:{1} Seconds:{2}", hh, mm, ss);
// Hours:2 Minutes:18 Seconds:20
Upvotes: 21
Reputation: 2681
You can use the TimeSpan.FromMinutes(minutesInDouble)
, pass the above value in double format.
For more information - check MSDN link here
Upvotes: 26