Simpler Datenum
#3
Actually, I'm going to post this demo to demonstrate how to calculate the day (1-366) in leap year and non-leap year calendar periods. I believe your deo only provides the accumulative days in a leap year event, but correct me if I'm wrong.



Code: (Select All)
INPUT "month-day-year as 'xx-xx-xxxx': ", a$
month$ = LEFT$(a$, 2)
day$ = MID$(a$, 4, 2)

a1 = VAL(MID$(a$, 7, 4)): ly = 0
IF a1 MOD 4 = 0 AND VAL(month$) > 2 THEN ' Check to add a day if leap year.
    IF a1 MOD 100 = 0 THEN
        IF a1 MOD 400 = 0 THEN ly = 1
    ELSE
        ly = 1
    END IF
END IF

datenum$ = _TRIM$(STR$(VAL(MID$("000031059090120151181212243273304334", VAL(month$) * 3 - 2, 3)) + VAL(day$) + ly))
datenum$ = MID$("00", LEN(datenum$)) + datenum$

PRINT a$
PRINT month$
PRINT day$
PRINT datenum$;: IF ly THEN PRINT " Leap year day included."
SLEEP
CLS
RUN


Note that 1700, 1800 and 1900 were not a leap year, but 2000 was.

I think Steve even has a one-liner for leap year calculation.

Anyway, feel free to add any of this info / code to your routine if you like, update /edit your code, etc. I don't get bent because my post no longer represents changes another poster makes, unless of course they are doing it to make me look stupid. My wife takes offense at that.... because it's her job.

Pete
Reply


Messages In This Thread
Simpler Datenum - by doppler - 05-04-2022, 04:43 PM
RE: Simpler Datenum - by Pete - 05-04-2022, 05:38 PM
RE: Simpler Datenum - by Pete - 05-04-2022, 07:10 PM
RE: Simpler Datenum - by dcromley - 05-05-2022, 04:49 AM
RE: Simpler Datenum - by Pete - 05-05-2022, 05:35 AM
RE: Simpler Datenum - by doppler - 05-05-2022, 02:10 PM
RE: Simpler Datenum - by Pete - 05-05-2022, 02:22 PM
RE: Simpler Datenum - by euklides - 05-07-2022, 07:59 AM
RE: Simpler Datenum - by doppler - 05-07-2022, 01:27 PM
RE: Simpler Datenum - by euklides - 05-08-2022, 11:59 AM



Users browsing this thread: 3 Guest(s)