Calculate a Fractional Number of Years Difference Between Two Dates in SQL
October 29, 2008 Hey, Mike
Is there anything new in SQL that will calculate the difference between two dates and return a fractional number of years? For example: “2007-09-10”–“1997-01-01” should return 10.69 years. The normal DB2 SQL function to return a difference between two timestamps (TIMESTAMP_DIFF) will not return fractional values as your calculation requires. However, if super accuracy isn’t a great need, there is an easy way to do this. Simply calculate the number of days between the two dates to get the number of days difference. Then divide the result by 365.2425, which is the average number of days in the Gregorian calendar, |