'******************************************** '* Compute number of days between two dates * '* ---------------------------------------- * '* Ref.: "Mathématiques par l'informatique * '* individuelle (1) par H. Lehning * '* et D. Jakubowicz, Masson, Paris, * '* 1982" [BIBLI 06]. * '******************************************** ' Note: The two dates must be between 01/01/1901 ' and 12/31/2099 to avoid treatment of special ' "secular" years, such as 1800, 1900, 2100... ' (2000, a multiple of 400, is a normal year!) ' ' The first date is M, D, Y ' N, number of days between first date and fictitious ' starting date 01/00/1901, is given by formula: ' ' N = INT(365,25*(Y-1901)+A(M)+D) ' ' where A(M) is given by table below: ' ' M 1 2 3 4 5 6 7 8 9 10 11 12 ' A(M) 0 31 59,25 90,25 120,25 151,25 181,25 212,25 243,25 273,25 304,25 334,25 ' ' First N is saved in R. ' ' The second date is again M, D, Y ' N is again computed with same formula. ' ' Final result is R - N. '************************************************** DIM A(12) A(1) = 0: A(2) = 31: A(3) = 59.25: A(4) = 90.25: A(5) = 120.25: A(6) = 151.25 A(7) = 181.25: A(8) = 212.25: A(9) = 243.25: A(10) = 273.25: A(11) = 304.25: A(12) = 334.25 10 CLS PRINT PRINT " Compute number of days between two dates" PRINT " (from 01/01/1901 to 12/31/2099)" PRINT PRINT " Enter first date (M,D,Y): "; GOSUB 1000 R = N PRINT " Enter second date (M,D,Y): "; GOSUB 1000 R = N - R PRINT PRINT " Number of days: "; R PRINT END 1000 INPUT "", M, D, Y N = 365.25 * (Y - 1901) + A(M) + D N = INT(N) RETURN 'end of file ndays.bas