## Revised routine RD2STD

/* here is the revised routine for RD2STD */ /* put it in mbr = RD2STD in QREXSRC */ /* convert rata die (RD) to USA format MM/DD/YYYY; from the RD, extract the number of 400 year periods and multiply by 400; take remainder of RD/146097 = RD//146097 and extract the number of 100 year periods and multiply by 100 ... etc. the sum of these will give the year with one correction: which is explained in the notes along with the last factor of year calculation Uses STD2RD() & Leap() Bob Hamilton; 09 May 2000. Tested from RD = 0 thru RD = 146097 ( 01Jan 0001 thru 01 Jan 0401 */ */ rd2std: arg RD; N400 = RD%146097 ; REM400 = RD//146097; n100 = REM400%36524; rem100 = rem400//36524 ; n4 = rem100%1461 ; rem4 = rem100//1461; N1 = rem4%365 ; year = (400*N400 + 100*N100 + 4*N4 + N1 +1 -(N100=4|N1=4)); year = right(year,4,'0'); NPDTY = RD - std2rd(year'0101'); Month = (12*(NPDTY + Correction(rd, year)) + 373)%367 ; day = RD - std2rd(year || right(month,2,'0') || '01' ) +1; return (year || right(month,2,'0') || right(day,2,'0') ); exit; correction: ARG RD, YEAR; select when rd < std2rd(year'0301') then return 0; when RD >= std2rd(year'0301') & Leap(year) then return 1; otherwise return 2; end;