home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION DAYNUM (date_val)
- *****************************************************************
-
- * Returns day number of year (day 1 = January 1st)
-
- * Copyright(c) 1991 -- James Occhiogrosso
-
- LOCAL counter := limit := num_days := 0, old_date := ''
-
- 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
-
- ELSEIF MONTH(date_val) = 1
- * Return actual day if date value is in January
- RETURN DAY(date_val)
-
- ENDIF
-
- * Save current date setting and set date to American
- old_date = SET(_SET_DATEFORMAT, 'mm/dd/yyyy')
-
-
- * Limit loop iterations
- limit = MONTH(date_val) - 1
-
- FOR counter = 1 TO limit
-
- * Count number of days in each month from start
- * of year to one month before passed date
-
- num_days = num_days + LASTDAY(CTOD( ;
- LTRIM(STR(counter)) + '/01/' + ;
- LTRIM(STR(YEAR(date_val))) ))
-
- NEXT
-
- * Restore old date setting
- SET(_SET_DATEFORMAT, old_date)
-
- * Add number of days for current month and return
- RETURN num_days + DAY(date_val)
-
-