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

How to calculate date diff in Year month & days format

Hi All,

I have data with DOJ, I wanted to calculate No of Year, Month & days for the employees in straight table .

Expected format is : 1 Year 1 Month 16 days.


TEST.PNG

Attached test qvw file. How to achieve this?

Thanks!

1 Solution

Accepted Solutions
sunny_talwar

Try this

=IF

(Today() <= AddYears(DOJ,1),'0 Years ',

Age(Today(),DOJ) & ' Years ')

&

IF(MONTH(Today()) = MONTH(DOJ),'0 Months ',

IF(DAY(DOJ) < DAY(Today()), fabs(MONTH(Today())-Month(DOJ)) & ' Months ',

((MONTH(Today())+12)-Month(DOJ))-1  & ' Months '

))

&

IF(MONTH(Today()) = MONTH(DOJ),DAY(Today()) - DAY(DOJ) & ' Days',

IF(DAY(Today()) > DAY(DOJ),DAY(Today()) - DAY(DOJ) & ' Days',

DAY(DATE(Interval(Today() - DOJ)))-1 & ' Days'

))

Took it from here:

Difference between two dates in Year,Month and ... | Qlik Community

View solution in original post

4 Replies
sunny_talwar

Try this

=IF

(Today() <= AddYears(DOJ,1),'0 Years ',

Age(Today(),DOJ) & ' Years ')

&

IF(MONTH(Today()) = MONTH(DOJ),'0 Months ',

IF(DAY(DOJ) < DAY(Today()), fabs(MONTH(Today())-Month(DOJ)) & ' Months ',

((MONTH(Today())+12)-Month(DOJ))-1  & ' Months '

))

&

IF(MONTH(Today()) = MONTH(DOJ),DAY(Today()) - DAY(DOJ) & ' Days',

IF(DAY(Today()) > DAY(DOJ),DAY(Today()) - DAY(DOJ) & ' Days',

DAY(DATE(Interval(Today() - DOJ)))-1 & ' Days'

))

Took it from here:

Difference between two dates in Year,Month and ... | Qlik Community

ajaysingh29
Contributor III
Contributor III
Author

Thanks Sunny!

migueldelval
Specialist
Specialist

Hi Ajay,

Check this please

=left((Today()-DOJ)/365,1)&' year '&(left(((Today()-DOJ)-(left(((Today()-DOJ)/365),1)*365))/30,1))&' Months'&((((Today()-DOJ)-(left(((Today()-DOJ)/365),1)*365)))-(left(((Today()-DOJ)-(left(((Today()-DOJ)/365),1)*365))/30,1)*30))&' days '

Regards

Miguel del Valle

ajaysingh29
Contributor III
Contributor III
Author

Hi Migule,

Thank you for your reply. Your solution is almost correct & working. However, in some case its not showing exact date diff.  Like if I select DOJ 5/1/16 its showing 1 Year & 1 Month. however with Sunny's solution its showing 1 Year, 0 month & 30 Days.

test11.PNG

Again, thank you for your efforts and help!