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

  1. *****************************************************************
  2. FUNCTION DAYNUM (date_val)
  3. *****************************************************************
  4.  
  5. * Returns day number of year (day 1 = January 1st)
  6.  
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8.  
  9. LOCAL counter := limit := num_days := 0, old_date := ''
  10.  
  11. IF date_val = NIL
  12.     * Default to current date if no value is passed
  13.     date_val = DATE()
  14.  
  15. ELSEIF VALTYPE(date_val) != 'D'
  16.     * Return zero if argument is wrong type
  17.     RETURN 0
  18.  
  19. ELSEIF MONTH(date_val) = 1
  20.     * Return actual day if date value is in January
  21.     RETURN DAY(date_val)
  22.  
  23. ENDIF
  24.     
  25. * Save current date setting and set date to American
  26. old_date = SET(_SET_DATEFORMAT, 'mm/dd/yyyy')
  27.  
  28.  
  29. * Limit loop iterations
  30. limit = MONTH(date_val) - 1
  31.  
  32. FOR counter = 1 TO limit
  33.  
  34.     * Count number of days in each month from start
  35.     * of year to one month before passed date
  36.  
  37.     num_days = num_days + LASTDAY(CTOD(         ;
  38.                LTRIM(STR(counter)) + '/01/' +   ;
  39.                LTRIM(STR(YEAR(date_val)))   ))
  40.  
  41. NEXT
  42.  
  43. * Restore old date setting
  44. SET(_SET_DATEFORMAT, old_date)
  45.  
  46. * Add number of days for current month and return
  47. RETURN num_days + DAY(date_val)
  48.  
  49.