(71B) Days From January 1, Days Between Dates - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (71B) Days From January 1, Days Between Dates (/thread-6478.html) (71B) Days From January 1, Days Between Dates - Eddie W. Shore - 06-30-2016 02:38 AM HP 71B – Day Counts Number of Days from January 1 D = Day M = Month L = Leap Year indicator (1 if the year is a leap year, 0 if it is not) Code: ```Program DAYJAN1 (183 bytes) 10 DESTROY D,M,L,N 12 INPUT “MONTH:”; M 14 INPUT “DAY:”; D 16 INPUT “LEAP? (Y=1,N=0):”; L 20 IF M>2 THEN 28 21 REM M<=2 22 N=IP(30.6*(M+13))+D-429 24 GOTO 32 27 REM M>2 28 N=IP(30.6*(M+1))+D+L-64 32 DISP “# DAYS:”; N``` Test 1: January 1 to May 29, non-leap year (L=0). Result: 148 Test 2: January 1 to May 29, leap year (L=1). Result: 149 Days between Dates M, D, Y: Month, Day, four-digit year Code: ```Program DDAYS (299 bytes) 10 DESTROY M1, M2, D1, D2, Y1, Y2, F1, F2 11 DESTROY F,M,D,Y,N,X,Z 12 INPUT “1: M,D,Y:”; M1, D1, Y1 13 INPUT “2: M,D,Y:”; M2, D2, Y2 15 M=M1 @ D=D1 @ Y=Y1 17 GOSUB 40 19 F1=F 21 M=M2 @ D=D2 @ Y=Y2 23 GOSUB 40 25 F2=F 27 N=F2-F1 29 DISP “# DAYS:”; N 31 STOP 40 IF M>2 THEN X=IP(.4*M+2.3) ELSE X=0 42 IF M>2 THEN Z=Y ELSE Z=Y-1 44 F=365*Y+31*(M-1)+D+IP(Z/4)-X 46 RETURN``` Test 1: January 2, 2015 to March 17, 2016 (1,2,2015 to 3,17,2016). Result: 440 Test 2: March 14, 1977 to June 29, 2016 (3,14,1977 to 6,29,2016). Result: 14352