February 22, 2008, 02:26 PM
newtofocusHelp with DATEDIF
I need help from WebFOCUS gurus out there. I am trying to get the difference between two dates using DATEDIFF but gett wrong result. Here is the code that I am using.
-SET &XDATE_FRM_YYMM='&DATE_FRM_YY.EVAL'|'&XDATE_FRM_MM.EVAL';
-SET &AYM1 = EDIT(&XDATE_FRM_YYMM,'999999');
-SET &DATE_FROM=AYM(&AYM1,'-1','I6');
-SET &MON_BEG_DATE = EDIT(&DATE_FROM,'999999') | '01';
-
-SET &DATE_TO ='&DATE_TO_YY.EVAL'|'&XDATE_TO_MM.EVAL';
-SET &MON_END_DATE = EDIT(&DATE_TO,'999999') | '31';
-SET &MONTH_DIFF = DATEDIF(&MON_BEG_DATE,&MON_END_DATE,'M');
When my month begining date is 20071001 and end date is 20080131, I am getting the difference as 299.
Thanks.
February 22, 2008, 05:32 PM
FrankDutchI would ad some debug lines to your code to evaluate the intermediate results.
Start with
-SET &ECHO=ALL;
then at the end I would do some type commands
If you put in the last line
-SET &MONTH_DIFF=DATEDIF(20071001,20080131,'M');
What is the result? what you expect (4) than this line is ok. And so on.
Did you buy the book "Almost 1001 ...."
February 23, 2008, 01:34 PM
Danny-SRLHi,
Your problem is that DATEDIF works with FOCUS dates and not with LEGACY dates (which is what one has in Dialog Manager). Try the following:
-SET &MON_BEG_DATE ='200701';
-SET &MON_END_DATE = '200801';
-SET &MONTH_DIFF = YM(&MON_BEG_DATE,&MON_END_DATE,'I3');
-TYPE &MONTH_DIFF &MON_BEG_DATE &MON_END_DATE