Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Date function to know how many days a month have

Hi

There is a function where given a month (a field containing it) returns how many days it have???

Jan then 31, Feb the 28, etc...

or one that returns the last day of a month...

Thxs in advance

7 Replies
johnw
Champion III
Champion III

I'm not aware of a specific function. Perhaps this:

ceil(monthend(Date)-monthstart(Date))

Though that requires a date, not just a month. But then, you have to know what the year is anyway, or you don't know how many days February has. And the actual day of the date does matter. So if all you had was a year and a month, you could do this:

ceil(monthend(makedate(Year,Month,1))-makedate(Year,Month,1))

If you always want 28 days for February, you can hardcode a year with 28 days in February:

ceil(monthend(makedate(2010,Month,1))-makedate(2010,Month,1))

And you could always make your own mapping:

[Days in Month]:
LOAD * INLINE [
Month, Days in Month
1, 31
2, 28
3, 31
etc.
];

Not applicable
Author

I decide to use just monthend, and i got what i needed!

Thxs a lot!

johnw
Champion III
Champion III

Heh, not sure what expression you used, but you made me realize that day(monthend(Date)) works and is much simpler than my previous suggestions. Is that what you did?

Not applicable
Author

Yes, I did that exactly...

Not applicable
Author

The question may be stupid but ...

when i use the following inline table, how can i link the days to the months? When i select Jannuary i want my MaxOrderDate to change to 31.1.2010 instead of 29.1.2010 (because there are NO sales the last two days of January of 2010)

[Days in Month]:
LOAD * INLINE [
Month, Days in Month
1, 31
2, 28
3, 31
etc.

etay_netintent
Partner - Contributor III
Partner - Contributor III

Hi

I'm not sure if this is what you are aiming at - given that you have a month and a day you can use

MakeDate(2010, Month,Days in Month) AS Date to get the corresponding date.

I hope this helps

Etay Elazar

Not applicable
Author

i am going to compare for example the sales of January of 2010 with the sales of January of 2009,

but when i select January, Qlikview relates to the sales of january of 2010, so when there are NO sales on 31 january, he is just calculating e.g. with 29 days of january,

and this means that he is comparing them with the figures of 2009 of 1st till 29th January, I want him to compare JANUARY with JANUARY

From my point of view i have to use an applymap function (applymap like one post before, months and days of month) but do not exactly know how to manage this.

Hope you can help me,

Christoph