Discussion:
Need help with time maths
(too old to reply)
Clinton M James
2007-03-19 14:16:45 UTC
Permalink
Raw Message
ive been racking my brain for one simple way to convert a time but cannot
wok it out.

It will be in a computer program so i have the ability to use absolute
values if any part of the equation has a negatvie value, if required.

ok I have a spreadsheet whereby it goes through and subtracts things, such
as times

So say it saw 20 weeks 15 hours 12 minutes and then saw 10 weeks 22 hours
and 48 minutes, it would mius each column to make 10 weeks, -7 hours and -36
mins.

Problem is i would like to convert this result back to a normal time.

The program knows how many hours per week, such as 38 in the example given.

I need this to apply to a variety of hours, so say i have the result but a
different amount of hours to convert it over.. 35 hours, 40 hours, etc.

Thing is too, the hours and mins arent always in defecit as the example is
either, therefoer it will need to accommodate positive and negative results
to convert it back to weeks horus mins over the specified hours and mins per
week - oh thats another thing, hours per week arent always whole numbers
either, it could be 37.5 hours.. I prefer to work in full weeks hours mins
rather than breaking it into decimals so to protect data accuracy such as
won't be occurring when any decimials have no set end - eg, 1/3 2/3 results
can intefer with the accuracy, therefore working with the 3 components is
preferred to changing them into 1 number (37 hours 30 mins rather than
37.5).

help is appreciated
Barb Knox
2007-03-19 21:19:25 UTC
Permalink
Raw Message
In article
Post by Clinton M James
ive been racking my brain for one simple way to convert a time but cannot
wok it out.
It will be in a computer program so i have the ability to use absolute
values if any part of the equation has a negatvie value, if required.
ok I have a spreadsheet whereby it goes through and subtracts things, such
as times
So say it saw 20 weeks 15 hours 12 minutes and then saw 10 weeks 22 hours
and 48 minutes, it would mius each column to make 10 weeks, -7 hours and -36
mins.
Problem is i would like to convert this result back to a normal time.
The program knows how many hours per week, such as 38 in the example given.
I need this to apply to a variety of hours, so say i have the result but a
different amount of hours to convert it over.. 35 hours, 40 hours, etc.
Thing is too, the hours and mins arent always in defecit as the example is
either, therefoer it will need to accommodate positive and negative results
to convert it back to weeks horus mins over the specified hours and mins per
week - oh thats another thing, hours per week arent always whole numbers
either, it could be 37.5 hours.. I prefer to work in full weeks hours mins
rather than breaking it into decimals so to protect data accuracy such as
won't be occurring when any decimials have no set end - eg, 1/3 2/3 results
can intefer with the accuracy, therefore working with the 3 components is
preferred to changing them into 1 number (37 hours 30 mins rather than
37.5).
help is appreciated
Do all arithmetic (your subtractions) in terms of exact minutes.
Converting WW,HH,MM to exact minutes is easy:
minutes = MM + HH*60 + WW*minutes_per_week
Converting minutes back to WW,HH,MM is a little trickier:
Start with the absolute value of minutes, remembering the sign.
WW = floor(minutes / minutes_per_week)
HH = floor((minutes - WW*minutes_per_week) / 60)
MM = minutes - WW*minutes_per_week - HH*60
Finally, if the original sign of minutes was negative, negate each
of WW,HH,MM.
--
---------------------------
| BBB b \ Barbara at LivingHistory stop co stop uk
| B B aa rrr b |
| BBB a a r bbb | Quidquid latine dictum sit,
| B B a a r b b | altum viditur.
| BBB aa a r bbb |
-----------------------------
Loading...