Focal Point
[CLOSED] Need help with DATEDIF

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/988103414

April 08, 2010, 04:58 AM
Micheal
[CLOSED] Need help with DATEDIF
Hello

I'm having problems getting the DATEDIF function to work correctly.

This is what I'm trying to do:

I want to calculate the difference between two dates so I thought I could accomplish this with:

-SET &dateDiff = DATEDIF(20100401, 20100402, 'D');

This works as expected and returns a difference of 1 day.

However, if I try the following:

-SET &dateDiff = DATEDIF(20100301, 20100401, 'D');

I would have thought this should return a difference of 31 days, instead it returns 100. I don't know why it does this.

To get around this issue I tried the following:

-SET &dateDiff = DATEDIF('01 MAR 2010', '01 APR 2010', 'D');

This worked correctly and calculated the difference as 31 days. However, I need to pass these dates into the DATEDIF function as variables. The first date is when the report was created, the second the current date. To do this I've used the following:

-* the first date
-SET &startDate = '20100401';

-* get the current date
-SET ¤tDate = TODAY(A10);

-* format the current date
-SET ¤tDate = EDIT(¤tDate,'$$$$$$9999')|EDIT(¤tDate,'99')|EDIT(¤tDate,'$$$99');

-* convert to '01 APR 2010' format
-SET &formatCurrentDate = CHGDAT('YYMD', 'DMYYT', ¤tDate, 'A17');
-SET &formatStartDate = CHGDAT('YYMD', 'DMYYT', &startDate, 'A17');

-* calculate difference
-*SET &dateDiff = DATEDIF(&formatStartDate, &formatCurrentDate, 'D');

When I run this I get the following error:

(FOC36355) INVALID TYPE OF ARGUMENT #2 FOR USER FUNCTION DATEDIF

It doesn't appear to like me passing in the date in variables if its of the format '01 APR 2010'

I'm now stumped.

I would be grateful for any assistance you can provide.

Thanks

Micheal

This message has been edited. Last edited by: Kerry,
April 08, 2010, 07:18 AM
Dan Satchell
If you use date strings instead of Smart Dates, function DATEDIF requires separators between the year, month, and day portions of the date string, and single quotes around the entire string. The code below seems to work.

-SET &STARTDATE = '20100401';
-SET &START_DATE = EDIT(&STARTDATE,'9999/99/99');
-SET &DATEDIFF = DATEDIF(&START_DATE.QUOTEDSTRING,&DATEYYMD.QUOTEDSTRING,'D');

This message has been edited. Last edited by: Dan Satchell,


WebFOCUS 7.7.05
April 08, 2010, 05:47 PM
Waz
Have a look at this Post

It uses the DATEDIF function, and should work for you.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!