1. Date conversions
Hi:
Does anyone have a routine for converting dates in the
"Day of our lord Bill Gates" format, i.e. days counted
starting with 01/01/1980, into normal MM/DD/YYYY format?
Record Actual date BG day bytes as stored
1 01/01/1980 1 25 72 0 0 {37,114,0,0}
2 01/02/1980 2 26 72 0 0 {38,114,0,0}
3 02/01/1980 32 44 72 0 0 {68,114,0,0}
4 01/01/1981 367 93 73 0 0 {147,115,0,0}
5 12/31/1981 731 FF 74 0 0 {255,116,0,0}
6 05/01/1999 7061 B9 8D 0 0 {185,141,0,0}
7 05/02/1999 7062 BA 8D 0 0 {186,141,0,0}
8 05/03/1999 7063 BB 8D 0 0 {187,141,0,0}
9 06/01/1999 7092 D8 8D 0 0 {216,141,0,0}
10 12/31/1999 7305 AD 8E 0 0 {173,142,0,0}
11 01/01/2000 7306 AE 8E 0 0 {174,142,0,0}
These are snipped from some VBasic data files, with the
"Actual dates" typed in by me. I'll be getting new files
every day, which I must turn into reports.
It would be really nice to be able to read the dates!
Thanks, (please reply before 7092 ADBG)
Irv
2. Re: Date conversions
From: Irv
>Does anyone have a routine for converting dates in the
>"Day of our lord Bill Gates" format, i.e. days counted
>starting with 01/01/1980, into normal MM/DD/YYYY format?
I tried it and came up with the following, which seems to work okay (at
least on the test set). But if you're going to be dealing with years beyond
2080 you'd need to expand the table. And if you're going to be dealing with
'negative' years before 1980, you'd probably have to redo the whole thing...
--- BGDates ---
--year lookup table
sequence ey, em
integer x
ey = {}
x = 0
for y = 1980 to 2080 do
if not remainder( y, 4 ) then
if not remainder( y, 100 ) then
--century
if not remainder( y, 400 ) then
--leap century
x = x + 366
else
x = x + 365
end if
else
--leap year
x = x + 366
end if
else
x = x + 365
end if
ey = ey & x
end for
--month lookup table
em = {31,28,31,30,31,30,31,31,30,31,30,31}
global function BG_to_mmddyyyy( atom BGDay )
integer year, month, day, x
--atom BGDay
year = 1980
month = 1
day = 1
x = 1
while BGDay > ey[x] do
x = x + 1
end while
x = x - 1
if x then
year = year + x
BGDay = BGDay - ey[x]
end if
em[2] = 28
if not remainder( year, 4 ) then
if not remainder( year, 100 ) then
--century
if not remainder( year, 400 ) then
--leap year
em[2] = 29
end if
else
--leap year
em[2] = 29
end if
end if
for c = 1 to 12 do
if BGDay > em[c] then
BGDay = BGDay - em[c]
month = month + 1
else
exit
end if
end for
day = BGDay
return( {month, day, year} )
end function
--===== TEST CODE =====--
sequence testdates
testdates =
{ 1,
2,
32,
367,
731,
7061,
7062,
7063,
7092,
7305,
7306
}
for c = 1 to length( testdates ) do
printf( 1, "%02d/%02d/%4d\n", BG_to_mmddyyyy( testdates[c] ) )
end for
3. Re: Date conversions
> 1 01/01/1980 1 25 72 0 0 {37,114,0,0}
>11 01/01/2000 7306 AE 8E 0 0 {174,142,0,0}
Oh, just noticed the part about the way the bytes are stored. Conversion
to atoms appears to be a straightforward (b2 * #100 + b1 - 29220). Don't
know why that is, but I guess it could go back a few years (however many are
in 29220 days) before 1980, since 01/01/1980 is stored as 29221.
revised test code:
--===== TEST CODE =====--
sequence testdates
testdates =
{ 1,
2,
32,
367,
731,
7061,
7062,
7063,
7092,
7305,
7306
}
sequence testbytes
testbytes =
{ {#25, #72},
{#26, #72},
{#44, #72},
{#93, #73},
{#FF, #74},
{#B9, #8D},
{#BA, #8D},
{#BB, #8D},
{#D8, #8D},
{#AD, #8E},
{#AE, #8E}
}
for c = 1 to length( testdates ) do
printf( 1, "%02d/%02d/%4d\n", BG_to_mmddyyyy( testdates[c] ) )
end for
atom blah
for c = 1 to length( testbytes ) do
position( c, 15 )
blah = testbytes[c][2] * #100 + testbytes[c][1] - 29220
printf( 1, "%02d/%02d/%4d\n", BG_to_mmddyyyy( blah ) )
end for
4. Re: Date conversions
On Wed, 26 May 1999, Scott Murray wrote:
>
> Oh, just noticed the part about the way the bytes are stored. Conversion
> to atoms appears to be a straightforward (b2 * #100 + b1 - 29220). Don't
> know why that is, but I guess it could go back a few years (however many are
> in 29220 days) before 1980, since 01/01/1980 is stored as 29221.
>
Thanks for your help! (Yes, I forgot to mention that the Euphoria function
bytes_to_int() seems to work for the conversion, and then subtracting the
29220 gets you to square 1)
Regards,
Irv
5. Re: Date conversions
29220 days before 1980 is 1900, or in the computers reckoning, 00
Scott Murray wrote:
> > 1 01/01/1980 1 25 72 0 0 {37,114,0,0}
> >11 01/01/2000 7306 AE 8E 0 0 {174,142,0,0}
>
> Oh, just noticed the part about the way the bytes are stored. Conversion
> to atoms appears to be a straightforward (b2 * #100 b1 - 29220). Don't
> know why that is, but I guess it could go back a few years (however many are
> in 29220 days) before 1980, since 01/01/1980 is stored as 29221.
>
[snip code]
6. Re: Date conversions
Greg Phillips wrote:
>29220 days before 1980 is 1900, or in the computers reckoning, 00
Actually, if you want to be *really* picky (though I hope not *too* picky...
:) ), 29220 days before 1/1/1980 is really 12/31/1899. Why VB counts its
date values from 12/31/1899 = 1 is anyone's guess, though it could be that
VB thinks 1900 was a leap year (it wasn't).
Be seeing you,
Gabriel Boehme