Introduction


T
his book shows how to convert a given date to an absolute value representing the number of days that have passed since 1 AD. This is useful when the difference of 2 dates has to be calculated, e.g. to check if a timeout in days has been reached.

Get day number


T
his program is using a simple formula to determine the number of days. Every year has 365 days except for leap-years. In those year the February has 29 days. A year is a leap-year if it can evenly be divided by 4 unless it can evenly be divided by 100 except it can evenly be divided by 400. This means 2004 is a leap-year but 1900 was no leap-year and again 2000 was a leap-year (because it can be divided by 400).

'Author     : Daniel, Master Sourcerer at Kitana's Cas...
'Last change: March 3, 2004
'Email      : sourcerer@kitana.org


#DIM ALL


'Returns the number of days a month has in a specific ...
'Input : M& = month (1-12)
'        Y& = year
'Output: number of days in this month
FUNCTION MONTHDAYS&(M&,Y&)
  LOCAL D&,Z$

  Z$=CHR$(31,28,31,30,31,30,31,31,30,31,30,31)
  D&=ASC(Z$,M&)  'assume default number of days

  IF M&=2 THEN  'special handling for February
    '29 days if year/4 unless year/100 except year/400
    IF (Y& AND 3)=0 THEN
      IF (Y& MOD 400)=0 OR (Y& MOD 100)<>0 THEN D&=29
    END IF
  END IF

  MONTHDAYS&=D&
END FUNCTION



'Calculates how many days have passed from 1 AD to thi...
'Input : D& = day (1-31)
Arena Play Ground Throne Room Theatre Hall Library Back Print Next page Last page