Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

subtract month

How can I Substract 2 dates and only get the months

for example : (DD/MM/YYYY)

01/01/2010 - 01/01/2009 = 12

01/01/2010 - 01/01/2008 = 24

01/01/2010 - 15/01/2009 = 12

01/02/2010 - 01/06/2009 = 8

1 Solution

Accepted Solutions
Not applicable
Author


Rob Wunderlich wrote:
(year(date2) + month(date2)) - (year(date1) + month(date1)) <div></div>


I guess what Rob tried to do is simplify the formula, and yes indeed it can be simplified as:

=( year(makedate(2008,2,1)) - year(makedate(2006,8,1)) ) *12 + ( month(makedate(2008,2,1)) - month(makedate(2006,8,1)) )

View solution in original post

7 Replies
pover
Luminary Alumni
Luminary Alumni

This has some degree of inexactitud, but should work for the next 100 years well.

=12*div((makedate(2010,2,1)-makedate(2009,6,1)),365)

+

floor(mod((makedate(2010,2,1)-makedate(2009,6,1)),365)/28)

Regards.

Not applicable
Author

Hi there, try this:

floor

((monthstart(date#('01/01/2010','DD/MM/YYYY')) - monthstart(date#('15/01/2009','DD/MM/YYYY' ))) /30

)

Regards





Not applicable
Author

Hi again, Karl is right about precision, so I realized there's no need to do the calcaulation in terms of days, but only months, hence you can use the following expression, without any fear of loosing precision in any point of the upcoming years:

=( ( year(makedate(2008,2,1)) - year(makedate(2006,8,1)) ) + ( month(makedate(2008,2,1)) - month(makedate(2006,8,1)) ) /12 ) *12

Best Regards

pover
Luminary Alumni
Luminary Alumni

I agree.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

(year(date2) + month(date2)) - (year(date1) + month(date1))

Not applicable
Author


Rob Wunderlich wrote:
(year(date2) + month(date2)) - (year(date1) + month(date1)) <div></div>


I guess what Rob tried to do is simplify the formula, and yes indeed it can be simplified as:

=( year(makedate(2008,2,1)) - year(makedate(2006,8,1)) ) *12 + ( month(makedate(2008,2,1)) - month(makedate(2006,8,1)) )

Not applicable
Author

thanks a lot to all the members