Monday, August 27, 2018

NAV CAL - Date2DMY - How to get dateparts from dates in nav and pad with leading zeroes

cd := FORMAT(DATE2DMY(ChqDate,1));
cm := FORMAT(DATE2DMY(ChqDate,2));
cy := FORMAT(DATE2DMY(ChqDate,3));
ChqDateDD := PADSTR('',2-STRLEN(cd),'0') + cd;
ChqDateMM := PADSTR('',2-STRLEN(cm),'0') + cm;
ChqDateYYYY := cy;


On Cheque, use Max to get the nonblank value in the footer
--------------------------------------------------------------------------------
Function to return YYYYMMDD

DateToYYYYMMDD(Date : Date) : Text
cd := FORMAT(DATE2DMY(Date,1));
cm := FORMAT(DATE2DMY(Date,2));
cy := FORMAT(DATE2DMY(Date,3));
cd := PADSTR('',2-STRLEN(cd),'0') + cd;
cm := PADSTR('',2-STRLEN(cm),'0') + cm;

EXIT(cy+cm+cd);


Opposite function to convert from text to date
-----------------------------------------------------------------------
YYYYMMDD2DATE(Date : Text[20]) : Date
cd := COPYSTR(Date,9,2);
cm := COPYSTR(Date,6,2);
cy := COPYSTR(Date,1,4);
EVALUATE(icd,cd);
EVALUATE(icm,cm);
EVALUATE(icy,cy);
MyDate := DMY2DATE(icd,icm,icy);
EXIT(MyDate);


No comments:

Post a Comment