Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only. Moving forward, myibi is our community platform to learn, share, and collaborate. We have the same Focal Point forum categories in myibi, so you can continue to have all new conversations there. If you need access to myibi, contact us at myibi@ibi.com and provide your corporate email address, company, and name.


Connect to myibi
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]HDIFF rounding year

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED]HDIFF rounding year
 Login/Join
 
Silver Member
posted
Hello guys,

I am trying to get the equivalent of the Excel function YEARFRAC in WebFOCUS. YEARFRAC expresses the difference between two dates as a year fraction. I was trying to write code using HDIFF that I could use to math out the equivalent, but it isn't working for me.

So for example if I've got a start date of 08/26/2010 and an end date of 05/19/2012 and I use HDIFF to get the year difference
 
-*ENDDATE = 2012-05-19 00:00:00
-*STARTDATE = 2010-08-26 00:00:00

YEARS_BETWEEN/D12.0 = HDIFF(ENDDATE,STARTDATE,'YEAR','D12.2');

 


YEARS_BETWEEN will return a value of 2.0 (I'm guessing it is rounding up from 1.73 which is what YEARFRAC returns). How do I get it to express the value without rounding?

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


WebFOCUS 8.105M, Windows 10, App Studio
 
Posts: 47 | Registered: October 22, 2014Report This Post
Virtuoso
posted Hide Post
Try YEARS_BETWEEN/D12.2


Thank you for using Focal Point!

Chuck Wolff - Focal Point Moderator
WebFOCUS 7x and 8x, Windows, Linux All output Formats
 
Posts: 2128 | Location: Customer Support | Registered: April 12, 2005Report This Post
Silver Member
posted Hide Post
Changed the decimal point placement to D12.2, but it is still giving me the rounded number.

It just now shows 2.00 instead of just 2.


WebFOCUS 8.105M, Windows 10, App Studio
 
Posts: 47 | Registered: October 22, 2014Report This Post
Virtuoso
posted Hide Post
I would go with this instead

DEFINE FILE CAR
STARTDATE     /YYMD  = '20100826';
ENDDATE       /YYMD  = '20120519';
MM_BETWEEN    /D12.2 = DTDIFF(ENDDATE, STARTDATE, MONTH);
DD_BETWEEN    /D12.2 = DTDIFF(ENDDATE, STARTDATE, DAY);
END
TABLE FILE CAR
SUM STARTDATE
    ENDDATE
    MM_BETWEEN
    DD_BETWEEN
    COMPUTE YYMM_FRACTION /D6.3 = MM_BETWEEN / 12;
    COMPUTE YYDD_FRACTION /D6.3 = DD_BETWEEN / 365;
BY MODEL NOPRINT
WHERE READLIMIT   EQ 1;
WHERE RECORDLIMIT EQ 1;
END

That is giving you the number of month or days between the dates. You can then perform the maths to have it as a fraction of year.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
 
Posts: 2410 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013Report This Post
Virtuoso
posted Hide Post
I also tried this..


DEFINE FILE CAR
ENDDATE/YYMD = '20120519';
STARTDATE/YYMD = '20100826';
YEARS_BETWEEN/D12.2 = DTDIFF(ENDDATE,STARTDATE,YEAR);
END
TABLE FILE CAR
PRINT YEARS_BETWEEN
BY COUNTRY
END


And it gave back 2.00 as well, I think it doesn't look at the full date just the YEAR portion provided when doing the calculation


Thank you for using Focal Point!

Chuck Wolff - Focal Point Moderator
WebFOCUS 7x and 8x, Windows, Linux All output Formats
 
Posts: 2128 | Location: Customer Support | Registered: April 12, 2005Report This Post
Silver Member
posted Hide Post
quote:
Originally posted by MartinY:
I would go with this instead

DEFINE FILE CAR
STARTDATE     /YYMD  = '20100826';
ENDDATE       /YYMD  = '20120519';
MM_BETWEEN    /D12.2 = DTDIFF(ENDDATE, STARTDATE, MONTH);
DD_BETWEEN    /D12.2 = DTDIFF(ENDDATE, STARTDATE, DAY);
END
TABLE FILE CAR
SUM STARTDATE
    ENDDATE
    MM_BETWEEN
    DD_BETWEEN
    COMPUTE YYMM_FRACTION /D6.3 = MM_BETWEEN / 12;
    COMPUTE YYDD_FRACTION /D6.3 = DD_BETWEEN / 365;
BY MODEL NOPRINT
WHERE READLIMIT   EQ 1;
WHERE RECORDLIMIT EQ 1;
END

That is giving you the number of month or days between the dates. You can then perform the maths to have it as a fraction of year.


Got it! I have to use the HDIFF for DAYS rather than YEAR and divide by 365 to return the YEARFRAC equivalent. Thank you so much!


WebFOCUS 8.105M, Windows 10, App Studio
 
Posts: 47 | Registered: October 22, 2014Report This Post
Virtuoso
posted Hide Post
Will that return the correct value for you on 31st of December of a leap year?
That would be ~1.0027, which is >1.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Master
posted Hide Post
I've had a NFR sitting out there since 2011 asking IBI to address this issue. In my problem report that became the NFR, IBI said that DATEDIF truncates while HDIFF rounds. The NFR status says it is in "Programming" whatever that means. Hard to believe it would be in programming over 8 years. When I'm using date time fields I generally use Minutes as the unit. Then if I need fractional days, I divide by 1440 minutes per day. If I need fractional years, I divide by 525600 minutes per year or 527040 minutes per year the from and to dates cross a leap day.

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


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
 
Posts: 975 | Location: Oklahoma City | Registered: October 27, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]HDIFF rounding year

Copyright © 1996-2020 Information Builders