IBI WebFOCUS - Finding prior/future dates from current date

I have come across the situation many a times where we need to filter report data for:

1) 6 months prior to selected/system date.
2) Report should pull data for date greater than last 30 days.
3) Any other situation where you need 30 days prior, 1 year future date, 3 months after date from system date etc.

I feel it is worth sharing the below piece of code:

-SET &DATEINPUT = EDIT('&DATEYYMD.EVAL','9999$$$$$$')||EDIT('&DATEYYMD.EVAL','$$$$$99$$$')||EDIT('&DATEYYMD.EVAL','$$$$$$$$99');
-TYPE &DATEINPUT
-SET &DATE_30 = DATECVT((DATEADD((DATECVT(&DATEINPUT, 'I8YYMD', 'YYMD')), 'D', -30)), 'YYMD', 'I8YYMD');
-TYPE IN: &DATEINPUT / OUT: &DATE_30

In above example, I calculated date which is 30 days prior to currect date. In place of 'D', we can have 'M', 'Y' and 'BD' for Months, Year and Business days. If you need to calculate future date, there will not be any minus '-' sign with 30. Means the code will be:
-SET &DATE_30 = DATECVT((DATEADD((DATECVT(&DATEINPUT, 'I8YYMD', 'YYMD')), 'D', 30)), 'YYMD', 'I8YYMD');

Please share your thoughts/ feedback's. 
Happy coding in WebFOCUS!!!!

Comments

Popular posts from this blog

IBI WebFOCUS - Functions available and syntax to use

IBI WebFOCUS - Difference (Preference) between Join and Match:

IBI WebFOCUS - Testing and Debugging in WebFOCUS codes