Is there a way to return dates between in format year-months in Cognos reports?
Example: I've been using the following to figure out "age"
_years_between (current_date, [DateOfBirth]).
Result comes out as just the age in years.
I'm looking for a way to return Age in the following format: preferably
12 years, 6 months
But can work with just a numerical number like the below:
12.5
A simple expression should do:
cast(floor (_months_between (current_date, [DateOfBirth]) / 12), int) || ' years, ' ||
mod(_months_between (current_date, [DateOfBirth]), 12) || ' months'
You can even get fancy and omit the "s" in "years" or "months" if the value is 1. I'll leave that part to you.
...and here it is using the _age()
function as suggested by C'est Moi.
cast(floor(_age([DateOfBirth]) / 10000), int) || ' years, ' ||
cast(floor(mod(_age([DateOfBirth]), 10000) / 100), int) || ' months'