Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculate Age in Qlikview

Hi,

I'm new to qlikview I want to calculate age or difference between two date like in years,Months and in days

i get 1 solution on qlikcommunity but it didn't work as i want, it shows wrong age as

difference between '30-07-2013' and '30-08-2013' is only 1 month but solution gives me '0 Year 12 Months 29 Days'

which is wrong.

Please find attachments.

Regards,

12 Replies
qv_testing
Specialist II
Specialist II

Hi Swuehl,

it's not open here, please give me text..

thanks

Not applicable
Author

*DT1 is DoB

*DT2 is Second Day (Today)

age(DT2,DT1)&' Years '&

  if(day(DT2) >= day(DT1),

  mod((Year(DT2)*12+Month(DT2))-(Year(DT1)*12+Month(DT1)),12),

  if(mod((Year(DT2)*12+Month(DT2))-(Year(DT1)*12+Month(DT1)),12)=0,11,mod((Year(DT2)*12+Month(DT2))-(Year(DT1)*12+Month(DT1)),12)-1)) &' Months '&

  if(day(DT2) >= day(DT1),

  day(DT2)-day(DT1),

  DT2-addmonths(DT1,12*(age(DT2,DT1))+if(mod((Year(DT2)*12+Month(DT2))-(Year(DT1)*12+Month(DT1)),12)=0,11,mod((Year(DT2)*12+Month(DT2))-(Year(DT1)*12+Month(DT1)),12)-1)))

fashid
Specialist
Specialist

Hi swuehl,

I know this would be difficult but it would be really nice if you could please explain the logic behind your script for calculating age for.

I have failed to understand the actual logic of the individual fields that are calculated using functions (the purpose of creating the fields)

Regards,

Nadeem