Anyone got a date math routine?

Kenneth Brody kenbrody at bestweb.net
Tue Dec 4 13:32:51 PST 2007


Quoting Jay R. Ashworth (Tue, 4 Dec 2007 16:08:48 -0500):

> On Mon, Dec 03, 2007 at 04:29:48PM -0500, Kenneth Brody wrote:
[...]
>> Use date/time math to get the number of seconds between the date+time.
>> (Date minus date equals days.  Time minus time equals hours.)  Then,
>> use the following:
[...]
> Yep, that was my plan, to within delta.  I was just hoping someone'd
> written the code already.  :-)
>
> My issue -- the thing I figured would require testing, is that you
> can't actually just do the days and the hours, I'm pretty sure:
>
> You need to do the days, and convert to seconds, and then do
>
> ENDTIME - midnight == seconds to add
>
> and
>
> 23:59:59 - STARTTIME = seconds to subtract
>
> And *then* convert back.  No?
>
> Or is that an identity, mathematically, with the way you suggested
> doing it?

This is the difference between HMS and TIME.

Using TIME, 12:00:00 minus 13:00:00 equals 23:00:00.  (That is, noon
minus 13 hours is 11PM.)

Using HMS, 12:00:00 minus 13:00:00 equals -1:00:00.  (That is, negative
one hour.)

Using HMS, there is no need to split the time at midnight.

Take today at 6PM minus yesterday noon:

     Today minus yesterday = 1 day = 24 hours.
     18:00:00 minus 12:00:00 = 6:00:00 = 6 hours.

     24 hours plus 6 hours = 30 hours = the correct answer.

Now, today 6AM minus yesterday noon:

     Today minus yesterday = 1 day = 24 hours.
     6:00:00 minus 12:00:00 = -6:00:00 = negative 6 hours.

     24 hours plus negative 6 hours = 18 hours = the correct answer.

[...]

-- 
KenBrody at BestWeb dot net        spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com


More information about the Filepro-list mailing list