Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for
Did you mean:
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

2 Solutions

Accepted Solutions
MVP

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

Creator

Hi Swuehi, your solution works for me, but may I ask you how to identify if February has 28 or 29 Days?

For example, Feb-2023 has 28, and Feb-2024 has 29. Is there any way?

8 Replies
MVP

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

Anonymous
Not applicable

Do you have trxn date?

If yes, try with this expression:

=count(distinct Day(TrxnDate))

MVP

=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.

Specialist II

Hi Himanshi,

PFA Sample application

-Regards,

Vishal Waghole

Partner - Champion III

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:

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

Contributor III
Author

hi,

thanks to all of you for quick response.

Regards,

Himanshi

Contributor

Day(MonthEnd(YourDateFieldName))

Creator

Hi Swuehi, your solution works for me, but may I ask you how to identify if February has 28 or 29 Days?

For example, Feb-2023 has 28, and Feb-2024 has 29. Is there any way?