home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_LASTDA.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  1.5 KB  |  67 lines

  1. *****************************************************************
  2. FUNCTION LASTDAY (date_val)
  3. *****************************************************************
  4.  
  5. * Returns number of last day of the month for any date
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9.  
  10. LOCAL last_day, month_num, num_days
  11.  
  12. IF date_val = NIL
  13.     * Default to current date if no value is passed
  14.     date_val = DATE()
  15.  
  16. ELSEIF VALTYPE(date_val) != 'D'
  17.     * Return zero if argument is wrong type
  18.     RETURN 0
  19.  
  20. ENDIF
  21.  
  22. month_num = MONTH(date_val)
  23.  
  24. * Default month length is 31 days
  25. num_days = 31
  26.  
  27. DO CASE
  28.  
  29.     * Is it one of the 30 day months?  Thirty days hath ....
  30.     CASE month_num = 4 .OR. month_num = 6 .OR. ;
  31.          month_num = 9 .OR. month_num = 11
  32.  
  33.          * Yes, return 30
  34.          num_days = 30
  35.  
  36.     CASE month_num = 2
  37.  
  38.          * If it is February, check for leap year
  39.          * and return 28 or 29 accordingly.
  40.  
  41.          IF YEAR(date_val) % 4 = 0 .AND. ;
  42.              YEAR(date_val) % 100 != 0
  43.  
  44.              * If year is divisable by four, but not
  45.              * 100, it is a leap year.
  46.              num_days = 29
  47.  
  48.          ELSEIF YEAR(date_val) % 100 = 0 .AND. ;
  49.                 YEAR(date_val) % 400 = 0
  50.  
  51.              * If year is divisable by 100, it must also be
  52.              * divisable by 400 to be a leap year.
  53.  
  54.              num_days = 29
  55.  
  56.          ELSE
  57.  
  58.              * Otherwise, it is not a leap year.
  59.  
  60.              num_days = 28
  61.  
  62.          ENDIF
  63. ENDCASE
  64.  
  65. RETURN(num_days)
  66.  
  67.