Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
himanshi
New Contributor III

how to get no of days from a month

hi,

i have a field which contains month names and i want total  no. of days from the selection of month.

for example if someone select December then it should give 31 days.

how to achieve this.

Regards ,

Himanshi Dubey

1 Solution

Accepted Solutions

Re: how to get no of days from a month

May be Something like this:

Floor(MonthEnd(Today())) - Floor(MonthStart(Today())) + 1

or based on selection:

Floor(MonthEnd(Max(DateField))) - Floor(MonthStart(Max(DateField))) + 1

6 Replies

Re: how to get no of days from a month

May be Something like this:

Floor(MonthEnd(Today())) - Floor(MonthStart(Today())) + 1

or based on selection:

Floor(MonthEnd(Max(DateField))) - Floor(MonthStart(Max(DateField))) + 1

balrajahlawat
Esteemed Contributor

Re: how to get no of days from a month

Do you have trxn date?

If yes, try with this expression:

=count(distinct Day(TrxnDate))

MVP
MVP

Re: how to get no of days from a month

=Day(Monthend(Date#('December','MMMM')))

resp.

Day(Monthend(Date#(YourMonthField,'MMMM')))


You may need to take care of february in leap years, so maybe add year to the date string.

VishalWaghole
Valued Contributor II

Re: how to get no of days from a month

Hi Himanshi,

PFA Sample application

-Regards,

Vishal Waghole

Re: how to get no of days from a month

If you don't care about Feburary sometimes having 29 days, your simplest option may be to create a static inline table with NoOfDays and connect it to your calendar. Using a field makes your expressions simpler, and IMHO it may even make performance a tiny little bit better. Not sure of the last one, though.

DaysInMonth:

LOAD * INLINE [

MonthName, Days

January, 31

February, 28

March, 31

April, 30

May, 31

June, 30

July, 31

August, 31

September, 30

October, 31

November, 30

December, 31

];

You can also add a field DaysInMonth to your calendar, an fill it using the Day(MonthEnd(CalDate)) formula. That would take care of the leap years.

Best,

Peter

[Edit]: reread your OP, month names it was...

himanshi
New Contributor III

Re: how to get no of days from a month

hi,

thanks to all of you for quick response.

Regards,

Himanshi