!******************************************** !* 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]. * !* * !* F90 version by J-P Moreau, Paris. * !* (www.jpmoreau.fr) * !******************************************** !***************************************************************************** ! 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 N - R. !******************************************************************************* PROGRAM NDAYS REAL*4 A(12) REAL*4 N ! number of days INTEGER R ! number of days 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 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): ' call Calcul(A,N) R = N print *,' Enter second date (M D Y): ' call Calcul(A,N) R = N - R print *,'' print *,' Number of days: ',R print *,''; print *,'' stop end Subroutine Calcul(A,N) integer M,D,Y !month,day,year REAL*4 N,A(12) read *, M, D, Y N = 365.25 * (Y - 1901) + A(M) + D N = int(N) return end ! end of file ndays.f90