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
Marc
I figured out myself this date -difference thing too. Your examples were right. Your query works, but gives months- between and needs to be divided with 12 and rounded.
This is maybe simpler:
select integer(floor( (datefield1 - datefield2) / 10000 ) as age ...
OR
select...
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...
Thanks, it looks ok, but there is no MONTHS -function, at least not in UDB2 version 7 (NT). 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.
No solution in DB2?
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.
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)?
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)?
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.