time calculations

  • Thread starter Thread starter Stevie
  • Start date Start date
S

Stevie

I need to add hours & minutes, i.e. 1020:00 + 1020:00 = 2040:00. (HHHH:MM)
Excel calculates it using a 24 hour clock and I don't get the results I'm
looking for.
Do I need a formula to convert the time?
Or, would there be a special cell format.
 
Why not convert from hours and minutes to hours, and fractions of hours, and
then back again.

So 10:45 + 10:30---> 10.75+10.5=21.25 ---> 21:15.

Dale
 
Why not convert from hours and minutes to hours, and fractions of hours, and
then back again.

So 10:45 + 10:30---> 10.75+10.5=21.25 ---> 21:15.

Dale
 
Stevie said:
I need to add hours & minutes, i.e. 1020:00 + 1020:00 = 2040:00. (HHHH:MM)
Excel calculates it using a 24 hour clock and I don't get the results I'm
looking for.
Do I need a formula to convert the time?
Or, would there be a special cell format.


Are you trying to do this in Excel? If so, you should ask in an Office or
Excel newsgroup.

This is a programming group, so, as such, I would use a TimeSpan object as
follows:

static void Main(string[] args)
{
TimeSpan ts1 = new TimeSpan(10, 45, 0);
TimeSpan ts2 = new TimeSpan(10, 30, 0);
TimeSpan ts3 = ts1.Add(ts2);
int H = (int) Math.Floor(ts3.TotalHours);
double M = ts3.TotalMinutes - (60 * H);
Console.WriteLine(string.Format("{0}:{1}", H, M));
Console.ReadLine();
}
 
Stevie said:
I need to add hours & minutes, i.e. 1020:00 + 1020:00 = 2040:00. (HHHH:MM)
Excel calculates it using a 24 hour clock and I don't get the results I'm
looking for.
Do I need a formula to convert the time?
Or, would there be a special cell format.


Are you trying to do this in Excel? If so, you should ask in an Office or
Excel newsgroup.

This is a programming group, so, as such, I would use a TimeSpan object as
follows:

static void Main(string[] args)
{
TimeSpan ts1 = new TimeSpan(10, 45, 0);
TimeSpan ts2 = new TimeSpan(10, 30, 0);
TimeSpan ts3 = ts1.Add(ts2);
int H = (int) Math.Floor(ts3.TotalHours);
double M = ts3.TotalMinutes - (60 * H);
Console.WriteLine(string.Format("{0}:{1}", H, M));
Console.ReadLine();
}
 
Back
Top