Counts the days between two dates, allowing for leap years and for the century years that are not leap years.
RUN it and enter month, day and four-digit year for each date, earlier date first. The second year can be up to 88 years after the first; for longer spans add two runs together, as the article explains. ENTER repeats, and any other entry quits. The article gives 1K as the memory needed, but this listing is 1252 bytes before its variables and screen, so it needs 2K. Its example of July 7, 1881 to January 1, 1921 is a day too high: the program correctly prints 14422, because 1900 was not a leap year.
Reprinted from SYNC, January/February 1983.
Published in LISTing February 1989 (Calculating the Days).
Source Code
20 DIM N(12)
25 LET N(1)=0
30 LET N(2)=31
35 LET N(3)=59
40 LET N(4)=90
45 LET N(5)=120
50 LET N(6)=151
55 LET N(7)=181
60 LET N(8)=212
65 LET N(9)=243
70 LET N(10)=273
75 LET N(11)=304
80 LET N(12)=334
85 LET D=0
90 PRINT " M/D/Y"
100 PRINT "ENTER FIRST DATE: ";
110 INPUT M1
112 IF M1>12 THEN GOTO 110
120 PRINT M1;"/";
130 INPUT D1
132 IF D1>31 THEN GOTO 130
140 PRINT D1;"/";
150 INPUT Y1
160 PRINT Y1
170 PRINT "ENTER SECOND DATE: ";
180 INPUT M2
185 IF M2>12 THEN GOTO 180
190 PRINT M2;"/";
200 INPUT D2
205 IF D2>31 THEN GOTO 200
210 PRINT D2;"/";
220 INPUT Y2
225 IF Y2-Y1>88 OR Y2<Y1 THEN GOTO 220
230 PRINT Y2
240 FOR X=Y1 TO Y2-1
250 LET D=D+365
255 IF INT (X/100)*100=X AND INT (X/400)*400<X THEN GOTO 265
260 IF INT (X/4)*4=X THEN LET D=D+1
265 NEXT X
270 IF Y1=Y2 THEN LET D=365-D
275 IF INT (Y1/100)*100=Y1 AND INT (Y1/400)*400<Y1 THEN GOTO 285
280 IF INT (Y1/4)*4=Y1 AND M1>2 THEN LET D=D-1
285 IF INT (Y2/100)*100=Y2 AND INT (Y2/400)*400<Y2 THEN GOTO 300
290 IF INT (Y2/4)*4=Y2 AND M2>2 THEN LET D=D+1
300 LET D=D-N(M1)-D1
310 LET D=D+N(M2)+D2
315 IF Y1=Y2 THEN LET D=D-365
320 PRINT D;" DAYS APART"
330 INPUT Y$
340 CLS
350 IF Y$="" THEN GOTO 20Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.


