Focal Point
[SOLVED]Date difference Calculation

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

March 11, 2013, 04:06 AM
Mayank Agrawal
[SOLVED]Date difference Calculation
Hi,
I want to calculate the difference between two dates and the result should be in Months with values upto two decimal places.

If I am using the "DATEDIF" Function then it is truncating the results and not provinding the results updo two decimal places.

Can you please suggest any function available in webfocus 7.6.11 Version.
Thanking you.

This message has been edited. Last edited by: Mayank Agrawal,


7.6.11, Windows
Excel, HTML,PDF
March 11, 2013, 10:28 AM
Francis Mariani
I don't think you can work with decimals and dates. What does 1.2 months mean? You could extract days or hours or smaller measures and do the division yourself...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
March 11, 2013, 04:48 PM
Waz
quote:
What does 1.2 months mean


True!

What is a month ?, 31, 30, 28 days ?, 365 / 12 days ?, 365.25 / 12 days ?

Also what code did you use ?


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!

March 11, 2013, 11:38 PM
Mayank Agrawal
Francis I agree with you that it does not mean to have month like 1.2, but this is our business requirement.
We have to first calculate the month and then find out the average of all the records.
If I am using DATEDIF function,the result deviated from its actual value.

Also I have thought of first finding the number of days and then dividing by 30.4, but its a kind of approximate method.
If you find any solution please let me know.

Many Thanks.


7.6.11, Windows
Excel, HTML,PDF
March 12, 2013, 12:59 PM
Doug
You could base the decimal portion on a list of (days in months). and go from there.

(days in month list) = (1 31 2 28 3 31...) with an offset for leap year. Use (day of month) in you calculation with the associated days from your list...

I hope this helps. Smiler
March 13, 2013, 09:03 AM
jgelona
When we have to do this, this is how we do it:
MONTHS/D8.2=(HIGH_DATE-LOW-DATE)/30.4375;


This truncates to 2 digits.

If you want automatic rounding use the P format.

According to the documentation, using HDIFF requires using a D format (Floating Point Double Precision). All the examples show D12.2. However, it does not return fractions either. I asked IBI why have the 2 decimals if they are never used? They did not know so I put in a NFR. So that existing code would not be changed, I suggested using FDAY, FYEAR, etc. in the types for fractional days, years, etc.

It is in "Product Division" whatever that means. If you have a use for fractional date/time computations with DATEDIF or HDIFF, please do a NFR.

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.
March 13, 2013, 09:57 AM
John_Edwards
If you're coding a fractional month to a specific business requirement, then that business unit needs to provide you with their official calculation method.

It may be as simple as number of days divided by 30, it may be some strange arcane thing based on the phase of the moon. Regardless, that business unit calls the tune on their expected value. Contact them and ask for the official version. Without it you'll never clear their testing.

J.