# Re: Epoch Date Generator

bjorn@tt-tech.se
Fri, 22 Dec 1995 10:59:46 +0100

``` ----------
Fr=E5n:  "Josh R. Williams" <sponge@roc[SMTP:MIME @SMTP {"Josh R. Williams"=
=20
<sponge@rocco.nebula.net>}]
Skickat:   den 19 december 1995 05:44
Till:   seesat <seesat-l@iris01.plasm; WORKGROUP/MSMAIL/BJORN
Kopia:   Dave Ransom <rans7500@spaceli
Ang=E5ende: Epoch Date Generator

Josh R. Williams asked for YYDDD.ddd from current system date.

The following function is a modification of a formula I had in
QBasic/QuickBasic(/Visual Basic/CA Realizer...) for Julian dates.
The original function could handle the non-leap-years 1900,2100...
(with a small adjustment of 365.25#?). (This one does not want
the century digits in the first parameter!)

DEFINT H-N
DEFDBL A-G, O-Z
DIM d AS INTEGER, Y AS INTEGER
FUNCTION YYDDD (Y AS INTEGER, m, d AS INTEGER, HH, MM, SS AS INTEGER)
' Range 0<=3DY<=3D99, 0<M<=3D12, 0<D<=3D31, 0<=3D HH<=3D24, 0<=3DMM<=3D5=
9, 0<=3DSS<=3D59
YD =3D 1000# * Y - 63 + d + INT(30.6 * (m + 1 - 12 * (m < 3)))
YD =3D YD + SS / 86400# + MM / 1440# + HH / 24#
' JD =3D YD +346.5+ INT(365.25# * (Y - 1860 + (M < 3)))
YYDDD =3D YD + 365 * (m < 3) + (m > 2) * (Y =3D 4 * (Y \ 4))
END FUNCTION

' and here is a test program, also showing current date/time :

DECLARE FUNCTION d2 (s\$, ix%)
DECLARE FUNCTION YYDDD (Y%, m%, d%, HH%, MM%, SS%)

PRINT YYDDD(95, 12, 21, 13, 0, 1)

' Print YYDDD.dddddd for current PC time :
t\$ =3D TIME\$
a\$ =3D DATE\$
PRINT a\$, t\$;
PRINT YYDDD(d2(a\$, 9), d2(a\$, 1), d2(a\$, 4), d2(t\$, 1), d2(t\$, 4), d2(t\$, =20=
=20
7))

OPEN "O", #1, "epoch.txt"
FOR Y =3D 95 TO 98
FOR m =3D 1 TO 12
FOR d =3D 1 TO 31
PRINT #1,USING"## ## ## "; Y, m, d;
PRINT #1,USING"#####.######", YYDDD(Y, m, d, 23, 59, 59)
NEXT
NEXT
NEXT

FUNCTION d2 (s\$, ix)
d2 =3D VAL(MID\$(s\$, ix, 2))
END FUNCTION

------------------------------------------------------------
-- bjorn.gimle@online.dextel.se    +46-8-7428086          --
-- bjorn@tt-tech.se                +46-8-59095739         --
--(bjorn.gimle@duesenberg.se)      59.22371 N, 18.22857 E --
------------------------------------------------------------
```