Focal Point
[CLOSED] Calculate DATEDIF based on a 360 day year

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

October 13, 2011, 01:38 PM
David J James
[CLOSED] Calculate DATEDIF based on a 360 day year
Is there a way to calculate the difference between 2 dates in days based on a 360 day year, similar to excel's days360 function?

This message has been edited. Last edited by: Kerry,


Mainframe FOCUS 7.3.8 10.26.05 18.02
Windows, All Outputs
October 13, 2011, 02:20 PM
Mary Watermann
David,

Found this on the tech support:

  
[url=http://techsupport.informationbuilders.com/hottrack/70141087.html][/url]


Basically it is saying WF doesn't have such a function; however, there is technique that may help you on that URL.


WF 7.6.10, Windows, PDF, Excel
October 13, 2011, 02:22 PM
Dan Satchell
There may be other solutions, but one is to multiply the number of days calculated with DATEDIF by 72/73 (which is the same as the number of minutes in a 360 day year divided by the number of minutes in a 365 day year: 1440 / 1460).

DEFINE FILE CAR
 DATE1/YYMD WITH COUNTRY = '2010/01/01';
 DATE2/YYMD WITH COUNTRY = '2010/02/01';
 DATE3/YYMD WITH COUNTRY = '2011/01/01';
 DATE_DIFF_365M/I5 = DATEDIF(DATE1,DATE2,'D');
 DATE_DIFF_360M/I5 = DATE_DIFF_365M * 72 / 73 ;
 DATE_DIFF_365Y/I5 = DATEDIF(DATE1,DATE3,'D');
 DATE_DIFF_360Y/I5 = DATE_DIFF_365Y * 72 / 73 ;
END
-*
TABLE FILE CAR
 PRINT
  DATE1 DATE2
  DATE_DIFF_365M DATE_DIFF_360M
  DATE1 DATE3
  DATE_DIFF_365Y DATE_DIFF_360Y
 WHERE RECORDLIMIT EQ 1 ;
END

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


WebFOCUS 7.7.05
October 13, 2011, 04:03 PM
njsden
Cool! Thanks for that Dan. Good One



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 13, 2011, 04:16 PM
Dan Satchell
Actually, it makes more sense to just multiple the result of DATEDIF by 360/365. Don't know why I felt the need to state it in minutes.

 DATEDIF(DATE1,DATE2,'D') * 360 / 365 ;



WebFOCUS 7.7.05
October 13, 2011, 04:29 PM
njsden
Maybe because time is gold? Wink



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 13, 2011, 04:43 PM
Dan Satchell
Just occurred to me that leap years could present a problem. May be best to calculate the number of days in the year and use that number as the divisor for converting to 360 day equivalents.

DEFINE FILE CAR
 YEAR_BEG/YYMD WITH COUNTRY = '2008/01/01';
 YEAR_END/YYMD WITH COUNTRY = '2008/12/31';
 YEAR_DAYS/I5 = DATEDIF(YEAR_BEG,YEAR_END,'D') + 1 ;
 DATE1/YYMD WITH COUNTRY = '2008/02/01';
 DATE2/YYMD WITH COUNTRY = '2008/03/01';
 DATE3/YYMD WITH COUNTRY = '2009/01/01';
 DATE_DIFF_365M/I5 = DATEDIF(DATE1,DATE2,'D');
 DATE_DIFF_360M/I5 = DATE_DIFF_365M * 360 / YEAR_DAYS ;
 DATE_DIFF_365Y/I5 = DATEDIF(YEAR_BEG,DATE3,'D');
 DATE_DIFF_360Y/I5 = DATE_DIFF_365Y * 360 / YEAR_DAYS ;
END
-*
TABLE FILE CAR
 PRINT
  YEAR_BEG YEAR_DAYS
  DATE1 DATE2
  DATE_DIFF_365M DATE_DIFF_360M
  DATE3
  DATE_DIFF_365Y DATE_DIFF_360Y
 WHERE RECORDLIMIT EQ 1 ;
END



WebFOCUS 7.7.05
October 13, 2011, 04:49 PM
njsden
quote:
DATEDIF(DATE1,DATE2,'D') * 360 / 365 ;


Could the leap year issue be solved by slightly adjusting your original expression?

DATEDIF(DATE1,DATE2,'D') * 360 / 365.25 ;


Or would that be too simplistic?



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.