In Orcale there is a function MONTHS_BETWEEN and in SQL Server DateDiff which help to calculate age from a birthdate. Is there a similar function in DB2 to get a difference of dates (in months)?
Thank you, but I can't see how this works? Multiply years by 12? The problem is, that difference between
1990-06-19 and 2002-06-19 => 12 years, and the differnece 1990-06-20 and 2002-06-19 => 11 years.
Ifound a working solution with help from Sathyaram (dBforums):
select current date, date_1 , integer( floor( (current date - date_1 ) / 10000 )) as age from table_1.
This works now: difference between
1990-06-19 and 2002-06-19 => 12 years, and the difference 1990-06-20 and 2002-06-19 => 11 years.
Why i have to divide with 10000 is still unclear...
Dear angiole
In DB2 the difference comes in format yymmdd, that's why it must first be divided by 10000 to get eg 12,0512 and then "floored" to 12,0 and finally "integered" to 12, meaning the age of 12.
Ari
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.