>I am trying to add time values [HHHH:MM] that are in entity rows and I was wondering if anyone has seen a method to do this. I am aware of the TimeSpan() functions, etc. but these all roll-over the hours when it hits the 23 + 1 to Days. I need to add values like 123:15 + 50:46, etc which would equal 174:01 where the minutes roll into the hours but hours do not roll into days. I have a method in Visual FoxPro that does this very well but I did not want to reinvent the wheel in .NET if I do not have to.
I see from the MM thread that values are strings. So, assuming the added value should also be a string, something like:
public static class TimeFunctions
{
static char[] splitter = new char[] { ':' };
public static string AddTimes(string a, string b)
{
string[] sa = a.Split(splitter);
string[] sb = b.Split(splitter);
int mins = int.Parse(sa[1]) + int.Parse(sb[1]);
int hours = int.Parse(sa[0]) + int.Parse(sb[0]) + mins / 60;
return hours.ToString().PadLeft(4,'0') + ":" + (mins % 60).ToString().PadLeft(2,'0');
}
}
I know you could write this yourself - I'm just wasting time 'till the first coffee arrives :-}