Operating System - OpenVMS
1753529 Members
4908 Online
108795 Solutions
New Discussion юеВ

Re: Continuous day count

 
SOLVED
Go to solution
Hein van den Heuvel
Honored Contributor

Re: Continuous day count

>> I expected 8340 not 8338. Below is me running it:


A little late, but you are correct.
I managed to paste a wrong version of the
code.

The leapyear test should be done before the increment. Sorry.

That makes it 8339.
It becomes 8340 if you want to count inclusive of start and end date for a duration.

The reason why this reply is so late is because I wanted to point out that it was not
my intention to edit the file for a specific start, but to just use an early enough date to handle start and end.

I used 17_NOV_1858 because that's the OpenVMS limit.

Next I tried 1-JAN-1900 because that's the EXCEL base date for use with DATEVALUE.
Handy for testing I thought....
Except that those amateurs at Microsoft got it wrong!
They have year 1900 as a Leap Year! Argh!
So I wasted a good bit of time getting confused by that + my own calculation order problem.

Excel::
text datevalue
1/1/1900 1
2/28/1900 59
3/1/1900 61

2/8/2011 40582
4/10/1988 32243
8339

I guess a handy base date is 1/1/1970.
That's the Unix base date ( UTC )

The code below gives:

$ @DAY_SINCE_1_JAN_1970.COM 11-feb-2011:04:40
11-FEB-2011:04:40 is 15016 days since 1_jan_1970. Unix Epoch Seconds: 1297399200

Confirmed with:

$ perl -e "print time"
1297399257

and also

$ @DAY_SINCE_1_JAN_1970.COM 1-jan-1970
1-JAN-1970 is 0 days since 1_jan_1970. Unix Epoch Seconds: 0

$ @DAY_SINCE_1_JAN_1970.COM 2-jan-1970
2-JAN-1970 is 1 days since 1_jan_1970. Unix Epoch Seconds: 86400

$ type DAY_SINCE_1_JAN_1970.COM
$
$ target = 123 ! This integer will become a string if Convert time works
$ target = F$CVT(P1,"ABSOLUTE","DATE")
$ IF F$TYPE(target) .NES. "STRING" THEN EXIT 16
$ year = 1969
$ days = -365
$ target_year = 'F$CVT( target,,"YEAR")
$
$year_loop:
$ year = year + 1
$ IF F$CVTIME("1-MAR-''year' -1-",,"DAY") THEN days = days + 1
$ days = days + 365
$ IF year.LT.target_year THEN GOTO year_loop
$
$ date = "1-JAN-''year'"
$day_loop:
$ IF date .EQS.target THEN GOTO done
$ date = F$CVT("''date' +1-","ABSOLUTE","DATE")
$ days = days + 1
$ goto day_loop
$
$ done:
$ seconds = days*86400 + 3600*F$CVT(p1,,"HOUR") + 60*F$CVT(p1,,"MINUTE") + F$CVT(p1,,"SECOND")
$ write sys$output p1, " is ", days, " days since 1_jan_1970. Unix Epoch Seconds: ", seconds

Cheers,
Hein


btw... the website I referred to reports:

http://www.convertunits.com/dates/from/Apr+10,+1988/to/Feb+8,+2011

"The total number of days between Sunday, April 10th, 1988 and Tuesday, February 8th, 2011 is 8,339 days.

This is equal to exactly 22 years, 9 months, and 29 days.

This does not include the end date, so it's accurate if you're measuring your age in days, or the total days between the start and end date. But if you want the duration of an event that includes both the starting date and the ending date, then it would actually be 8,340 days.

The total time span from 1988-04-10 to 2011-02-08 is 200,136 hours.

This is equivalent to 12,008,160 minutes.

You can also convert 8,339 days to 720,489,600 seconds."

Hein


Niall76
Frequent Advisor

Re: Continuous day count

Thanks guys for all your help. It works perfectly.
Niall
Oswald Knoppers_1
Valued Contributor

Re: Continuous day count

Re. Hein,

"Except that those amateurs at Microsoft got it wrong!"

They claim it was Lotus who got it wrong:

http://support.microsoft.com/kb/214326

:-)

Oswald