Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
himanshi
Contributor III
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
sunny_talwar

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

View solution in original post

panosalexand
Creator
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?  

Thank you in advance

View solution in original post

8 Replies
sunny_talwar

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))

swuehl
MVP
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.

VishalWaghole
Specialist II
Specialist II

Hi Himanshi,

PFA Sample application

-Regards,

Vishal Waghole

Peter_Cammaert
Partner - Champion III
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:

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
Contributor III
Contributor III
Author

hi,

thanks to all of you for quick response.

Regards,

Himanshi

Juzhuxi
Contributor
Contributor

Day(MonthEnd(YourDateFieldName))

Capture.PNG

 

panosalexand
Creator
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?  

Thank you in advance