Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - time calculations

Reply
 
Old 05-12-2009   #1 (permalink)
Stevie


 
 

time calculations

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.
--
Stevie

My System SpecsSystem Spec
Old 05-12-2009   #2 (permalink)
Dale Atkin


 
 

Re: time calculations

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" <StevieO@xxxxxx> wrote in message
news:BF868F1C-1963-47EA-8E48-8EA7EA55DF4E@xxxxxx
Quote:

>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.
> --
> Stevie
My System SpecsSystem Spec
Old 05-12-2009   #3 (permalink)
Family Tree Mike


 
 

Re: time calculations

"Stevie" <StevieO@xxxxxx> wrote in message
news:BF868F1C-1963-47EA-8E48-8EA7EA55DF4E@xxxxxx
Quote:

>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.
> --
> Stevie

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();
}


--
Mike

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Windows System Time and Desktop time not matching up Vista General
Date time calculations PowerShell
Internet Time Synchronization Incorrect - Showing Standard Time PowerShell
One question about Windows Time Synchronize with Internet Time Ser Vista General
Demo of getting/setting time from an RFC867 time source PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46