Relevance to determine the last day of the month

Merely sharing information here. We had a client who needed to run a particular fixlet on the last day of each month. In researching we found no “canned” relevance for this so we quickly developed the following.

Here is a simple boolean to be used in fixlet relevance. All we do is see if tomorrow is the next month. By default we are the last day of the current month.

((month of (it + 1 *day)) = (month of it + 1 *month)) of (current date)

If you wish to know the date of the last day of the current month you can use this.

(current date + 1*month) - ((day_of_month of current date) as integer *day)

the latter would not be as easily implemented in fixlet relevance but could be valuable in a retrieved property and aid in reporting.

3 Likes

I think you forgot the * in the first relevance before day and month.

Ah, copy / paste error in the web form! I think somehow the posting stripped it as it’s missing in both the day and month calcs. Thank you for noticing that.

Nice, thanks for sharing!

There’s an older related thread as well, that can help if you want to do things like listing the last day of each month for the next year, at Next Month’s Date

Jason, I ran across that one when researching. It’s good relevance, thanks for linking it in this thread.

I considered posting this there as they are closely related, but I had a hard time resurrecting a 3 year old thread, LOL

(current date + 1*month) - ((day_of_month of current date) as integer *day)

I’ve done work on this before and I think this will fail if the current day of month is not a valid day of month for the next month (e.g. 31st March, 30th Jan).

This does not error.

((1 as day_of_month) & ((month_and_year of current date) + 1 * month)) - 1 * day

My tests:

q: (date ("05 Feb 2020") + 1*month) - ((day_of_month of date ("05 Feb 2020")) as integer *day)
A: Sat, 29 Feb 2020
T: 0.417 ms
I: singular date

q: (date ("30 Mar 2020") + 1*month) - ((day_of_month of date ("30 Mar 2020")) as integer *day)
A: Tue, 31 Mar 2020
T: 0.347 ms
I: singular date

q: (date ("31 Mar 2020") + 1*month) - ((day_of_month of date ("31 Mar 2020")) as integer *day)
E: Singular expression refers to nonexistent object.

q: (date ("29 Jan 2021") + 1*month) - ((day_of_month of date ("29 Jan 2021")) as integer *day)
E: Singular expression refers to nonexistent object.



q: ((1 as day_of_month) & ((month_and_year of date ("05 Feb 2020")) + 1 * month)) - 1 * day
A: Sat, 29 Feb 2020
T: 0.280 ms
I: singular date

q: ((1 as day_of_month) & ((month_and_year of date ("30 Mar 2020")) + 1 * month)) - 1 * day
A: Tue, 31 Mar 2020
T: 0.206 ms
I: singular date

q: ((1 as day_of_month) & ((month_and_year of date ("31 Mar 2020")) + 1 * month)) - 1 * day
A: Tue, 31 Mar 2020
T: 0.138 ms
I: singular date

q: ((1 as day_of_month) & ((month_and_year of date ("29 Jan 2021")) + 1 * month)) - 1 * day
A: Sun, 31 Jan 2021
T: 0.070 ms
I: singular date
2 Likes

Ah, thanks, I couldn’t remember why I started from the first day of the current month instead of today. That was it

Great catch! Thank you. I had only used this in limited reporting and had not seen the issue you pointed out. I guess it was just luck in when checks were being performed.

Thanks, it’s the edge conditions that lurk in the shadows.

You actually have to be out of luck to hit it when developing (only 6 or 7 days in any one year) but your action would fail to run 5 times a year (and, inevitably, the first failure will be several weeks after you wrote the relevance).

1 Like

Even works on Leap years!

q: (day_of_month 1  & current month_and_year) + month - day
A: Sat, 29 Feb 2020
2 Likes