/* ---------------------------------------------------------------- */ /* MMDDYY2B.REX: Convert MM/DD/YY date to Base format */ /* ---------------------------------------------------------------- */ /* Returns the number of days between the specified date and the */ /* "base" date (01 January 0001). */ /* ---------------------------------------------------------------- */ /* Syntax: */ /* r = MMDDYY2B(date) */ /* Examples: */ /* MMDDYY2B('9/30/1994') == 728200 */ /* MMDDYY2B('12-31-2001') == 730849 */ /* MMDDYY2B('10 10 1492') == 544859 */ /* MMDDYY2B(' 1/ 1/0001') == 0 */ /* ---------------------------------------------------------------- */ /* Argument must be a valid date in 'month/day/year' format. */ /* (Hyphens and/or spaces may also be used as delimiters.) */ /* Leading zeros are optional for 1-digit month and day numbers */ /* (e.g., '1/1/1994' is ok). A two-digit year YY is interpreted */ /* as being in the current century; all other years are taken */ /* literally. The result is an integer. */ /* ---------------------------------------------------------------- */ /* Compatible with the REXX date('Base') function; e.g.: */ /* date('Base') == MMDDYY2B(date('Usa')) */ /* wkday = MMDDYY2B('12-7-41')//7 /* 0=Mon ... 6=Sun */ */ /* See HELP REXX DATE for more information on the base date */ /* ---------------------------------------------------------------- */ /* See also: B2MMDDYY.REX */ /* ---------------------------------------------------------------- */ /* Thanks to Peter Baum for his excellent set of date algorithms */ /* (see ). This is a */ /* REXX implementation of his "Rata Die Algorithm" (section 5.1); */ /* only change is constant 306 to 307 because REXX base day 1 is */ /* one day later than RD 1. */ /* ---------------------------------------------------------------- */ /* 15 Sep 1994 Rex Swain, Independent Consultant, www.rexswain.com */ /* 18 Mar 2000 Completely recoded using Peter Baum's algorithm */ /* ---------------------------------------------------------------- */ parse arg args args = translate(args,' ','/-') /* Blank out / and - */ parse var args m d y /* ----- Default century to current century ----------------------- */ if 2 = length(strip(y)) then y = y + 100 * (date('S') % 1000000) /* ----- Peter Baum's algorithm ----------------------------------- */ z = y + (m-14) % 12 f = word('306 337 0 31 61 92 122 153 184 214 245 275',m) return d + f + 365*z + z%4 - z%100 + z%400 - 307