home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / calcbs.zip / CALCBSDT.CMD
OS/2 REXX Batch file  |  1994-07-25  |  1KB  |  48 lines

  1. /*  */
  2.  
  3. CalcBaseDate: Procedure
  4. /* routine to convert a date passed in YY/MM/DD format (assumes the date is 19YY/MM/DD )
  5.         to Base date format which is based upon an imaginary calendar date of 1/1/0001
  6.         it then assumes there is a leap year every 4 years and every 400 years but not
  7.         if the year is divisble by 100 */
  8.  
  9. /* initialize routine: */
  10.  
  11. NonLeap.=31
  12. NonLeap.0=12
  13. NonLeap.2=28
  14. NonLeap.4=30
  15. NonLeap.6=30
  16. NonLeap.9=30
  17. NonLeap.11=30
  18.  
  19. /* grab parameter and store it in cyear cmonth cdate */
  20.  
  21. parse arg cyear '/' cmonth '/' cdate ' ' .
  22.  
  23. /* grab year and convert it to YYYY */
  24.  
  25. fullyear = '19'||cyear
  26. numyears = fullyear -1
  27. basedays = numyears * 365
  28. QuadCentury = numyears % 400
  29. Century = numyears % 100
  30. LeapYears = numyears % 4
  31. basedays = basedays + (((LeapYears - Century) + QuadCentury) - 1)
  32.  
  33. do i = 1 to (cmonth -1)
  34.    if i <> '2' then
  35.         basedays = basedays + NonLeap.i
  36.    else /* find if it's a leap year or not */
  37.         if (fullyear // 4) > 0 then
  38.                 basedays=basedays + 28
  39.         else
  40.                 if ((fullyear // 100) = 0) & ((fullyear // 400) > 0) then
  41.                         basedays = basedays + 28  /* century not divisble by 400 */
  42.                 else
  43.                         basedays = basedays + 29 /* quad century or regular leap year */
  44. end /* do */
  45.  
  46. basedays = basedays + cdate
  47. return basedays
  48.