Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

I need to extract the exact number of years between two date.

Hello:

I need to extract the exact number of years between two date.

for Examplo,

If startdate = 30/04/2006

And

enddate = 15/04/2014

Result to obtain is 7 years and 11 months

To put a range for 1 to 7 years that person should not leave me.

Because it has more than 7 years

How do to limit that option and just go down the 7


The function age does not give me the exact years,


examplo:

=age('15/04/2014','30/04/2006')

We obtain: 7 years  with several months.

I need a function that I have fulfilled the seven years:

For examplo:

Of 1 to 7 years this age('15/04/2014','30/04/2006') not qualify,he have more time.

This Qualify age('15/04/2013','30/04/2006') 6 years with several months.


I need an exact function of completed years, not more

helpme

please

4 Replies
MK_QSL
MVP
MVP

LOAD

  *,

  If(Day(EndDate) >= Day(StartDate), MOD(MonthIDToday-MonthIDStartDate,12),

  If(MOD(MonthIDToday-MonthIDStartDate,12)=0,11,MOD(MonthIDToday-MonthIDStartDate,12)-1)) as AgeMonths;

LOAD

  *,

  Age(EndDate,StartDate) as AgeYears,

  Year(StartDate)*12+Month(StartDate) as MonthIDStartDate,

  Year(EndDate)*12+Month(EndDate) as MonthIDToday;

Load * Inline

[

  StartDate, EndDate

  30/04/2006, 15/04/2014

];

Now you can use

=AgeYears & ' Years and '& AgeMonths &' Months'

Not applicable
Author

Hi,

Another possibility:

If(AddYears(startdate,7)<=enddate, Floor((Year(enddate)-Year(startdate))*12+Num(Month(enddate))-Num(Month(startdate))+(Day(enddate)<Day(startdate))/12) & ' years ' & Mod((Year(enddate)-Year(startdate))*12+Num(Month(enddate))-Num(Month(startdate))+(Day(enddate)<Day(startdate)),12) & ' months')

This returns Null if there's more than 7 years, otherwise years and months as a string.

Hope this helps.

swuehl
MVP
MVP

The QV function

=age('15/04/2014','30/04/2006')


does return '7', not anything like '7 years and 11 month'.


I not sure why this doesn't work for you. See also your other thread on how to calculate Years, Month and Day difference between two dates, this has worked for you, right?




Clever_Anjos
Employee
Employee

Age function returns an integer, not a fraction.

=age('15/04/2014','30/04/2006') returns 7 not 7,<something>