Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

wanyunyang
Contributor

get month

If I have two dates 02/21/2017 & 01/26/2018, how could I get the number of months between these two dates?

1 Solution

Accepted Solutions
MVP
MVP

Re: get month

I prefer to define a MonthSequence field in my master calendar.

     ...

     Year(calDate) * 12 + Month(calDate) as MonthSequence,

     ...

In that case difference in months is simply the difference of the two month sequences.

If you want to do this in an expression, then you can do something similar

    =(Year(date1) * 12 + Month(date1)) - (Year(date2) * 12 + Month(date2))

4 Replies
adityaakshaya
Contributor III

Re: get month

Hi Wanyun,

You can use below expression to get number of months between these two dates.

=Round((date#(01/26/2018) - date#(02/21/2017))/30,0)

Regards,

Akshaya

PS - if you find this as correct/helpful, mark it as Correct/Helpful.

thiago_justen
Valued Contributor III

Re: get month

May be:

Interval(End_Date-Start_Date,'MM')

Thiago Justen Teixeira Gonçalves
WhatsApp: 24 98152-1675
Skype: justen.thiago
sumanta12
Contributor II

Re: get month

FLOOR(INTERVAL(DATE(DATE#('01/26/2018','MM/DD/YYYY'),'DD/MM/YYYY')-DATE(DATE#('02/21/2017','MM/DD/YYYY'),'DD/MM/YYYY'),'D hh:mm')/30)

MVP
MVP

Re: get month

I prefer to define a MonthSequence field in my master calendar.

     ...

     Year(calDate) * 12 + Month(calDate) as MonthSequence,

     ...

In that case difference in months is simply the difference of the two month sequences.

If you want to do this in an expression, then you can do something similar

    =(Year(date1) * 12 + Month(date1)) - (Year(date2) * 12 + Month(date2))

Community Browser