home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION LASTDAY (date_val)
- *****************************************************************
-
- * Returns number of last day of the month for any date
-
- * Copyright(c) 1991 -- James Occhiogrosso
-
-
- LOCAL last_day, month_num, num_days
-
- IF date_val = NIL
- * Default to current date if no value is passed
- date_val = DATE()
-
- ELSEIF VALTYPE(date_val) != 'D'
- * Return zero if argument is wrong type
- RETURN 0
-
- ENDIF
-
- month_num = MONTH(date_val)
-
- * Default month length is 31 days
- num_days = 31
-
- DO CASE
-
- * Is it one of the 30 day months? Thirty days hath ....
- CASE month_num = 4 .OR. month_num = 6 .OR. ;
- month_num = 9 .OR. month_num = 11
-
- * Yes, return 30
- num_days = 30
-
- CASE month_num = 2
-
- * If it is February, check for leap year
- * and return 28 or 29 accordingly.
-
- IF YEAR(date_val) % 4 = 0 .AND. ;
- YEAR(date_val) % 100 != 0
-
- * If year is divisable by four, but not
- * 100, it is a leap year.
- num_days = 29
-
- ELSEIF YEAR(date_val) % 100 = 0 .AND. ;
- YEAR(date_val) % 400 = 0
-
- * If year is divisable by 100, it must also be
- * divisable by 400 to be a leap year.
-
- num_days = 29
-
- ELSE
-
- * Otherwise, it is not a leap year.
-
- num_days = 28
-
- ENDIF
- ENDCASE
-
- RETURN(num_days)
-
-