/* ---------------------------------------------------------------- */ /* B2MMDDYY.REX: Convert Base format date to MM/DD/YYYY */ /* ---------------------------------------------------------------- */ /* Returns the date represented by the number of days since the */ /* "base" date (01 January 0001). */ /* ---------------------------------------------------------------- */ /* Syntax: */ /* r = B2MMDDYY(days) */ /* Examples: */ /* B2MMDDYY(0) == '01/01/0001' */ /* B2MMDDYY(544859) == '10/10/1492' */ /* B2MMDDYY(728200) == '09/30/1994' */ /* B2MMDDYY(730849) == '12/31/2001' */ /* ---------------------------------------------------------------- */ /* The argument must be an integer >= -307. The result is a date */ /* string in 'month/day/year' format. Month and day numbers are */ /* always formatted with two digits. Years are formatted with four */ /* digits (unless more are required, when year > 9999). */ /* ---------------------------------------------------------------- */ /* Compatible with the REXX date('Base') function; e.g.: */ /* date('Usa') == B2MMDDYY(date('Base')) */ /* tomorrow = B2MMDDYY(1+date('Base')) */ /* ---------------------------------------------------------------- */ /* Note that many REXX implementations have a built-in DATECONV */ /* function that may be used to perform this type of conversion. */ /* ---------------------------------------------------------------- */ /* See also: MMDDYY2B.REX */ /* ---------------------------------------------------------------- */ /* Thanks to Peter Baum for his excellent set of date algorithms */ /* (see ). This is a */ /* REXX implementation of his "Rata Die Number to Gregorian Date" */ /* algorithm (section 6.2.1, example 2); 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 rd /* ----- Peter Baum's algorithm ----------------------------------- */ z = rd + 307 h = 100*z - 25 a = h % 3652425 b = a - a%4 year = (100*b + h) % 36525 c = b + z - 365*year - year%4 month = (5*c + 456) % 153 day = c - word('0 31 61 92 122 153 184 214 245 275 306 337',month-2) if month > 12 then do year = year + 1 month = month - 12 end /* ----- Format result -------------------------------------------- */ if length(year) < 4 then year = right(year,4,'0') /* At least 4-digit year */ return right(month,2,'0') || '/' || right(day,2,'0') || '/' || year