Article View: aus.mathematics
Article #144Re: Need help with time maths
From: Barb Knox
Date: Mon, 19 Mar 2007 21:19
Date: Mon, 19 Mar 2007 21:19
57 lines
3481 bytes
3481 bytes
In article
<45fe9b50$0$17561$5a62ac22@per-qv1-newsreader-01.iinet.net.au>,
"Clinton M James" <fakeemail@yahoo.com> wrote:
> 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 |
-----------------------------
Technical Details
Message-ID:
<see-D5FCDC.09192020032007@lust.ihug.co.nz>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!seeReferences:
<45fe9b50$0$17561$5a62ac22@per-qv1-newsreader-01.iinet.net.au>Show Full Headers
Complete Article Headers
X-Google-Thread: 10d67e,1c2216881bdec7af X-Google-Attributes: gid10d67e,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!see From: Barb Knox <see@sig.below> Newsgroups: aus.mathematics Subject: Re: Need help with time maths Date: Tue, 20 Mar 2007 09:19:25 +1200 Organization: I'm not unemployed; I'm a consultant Lines: 57 Message-ID: <see-D5FCDC.09192020032007@lust.ihug.co.nz> References: <45fe9b50$0$17561$5a62ac22@per-qv1-newsreader-01.iinet.net.au> NNTP-Posting-Host: 203.118.157.47 X-Trace: lust.ihug.co.nz 1174339064 12192 203.118.157.47 (19 Mar 2007 21:17:44 GMT) X-Complaints-To: abuse@ihug.co.nz NNTP-Posting-Date: Mon, 19 Mar 2007 21:17:44 +0000 (UTC) User-Agent: MT-NewsWatcher/3.4 (PPC Mac OS X)