Setting Last day of month

I have the month and year and wanted to get the last day to set dynamically for my parameters thought this might help someone else

  1. The innermost if checks if adding one day to the 30th results in the same month. If it does, the month has 31 days. If not, it has 30 days.
  2. The middle if checks if adding one day to the 29th keeps it in the same month. If it does, it continues to the innermost if. If not, it directly returns 29.
  3. The outermost if starts with the 28th, and if adding one day keeps it in the same month, it proceeds to the middle if. If not, it directly returns 28.
2 Likes

It’s interesting seeing all the workarounds we have to come up with when we need something there isn’t a straightforward method to get it.

Here’s also another way to approach this:
Given the month and year, string together a date for the first day of that month and use parseDate() on that.
For this month, 10, and this year, 2023, we get 10-1-2023.
Then, add a month, so 11-1-2023.
Then, remove 1 day, so 10-31-2023.
Use a formatDate if you just need to get the day number.

image

7 Likes

so many ways to get to the same answer with different methods.

1 Like

Awesome stuff @Mr.Make thanks so much for hopping into the community and sharing this ‘cheat sheet’ with us. Super valuable stuff. :clap:

The same goes for @Donald_Mitchell , of course. Thanks for letting us know how you go about working with the last day of month in Make. :muscle:

:arrow_down: Oh and this is so true! It’s really interesting to see how different folks choose different approaches to certain concepts in Make :nerd_face:


Just FYI

On a similar note, there’s also this community post about scheduling your scenarios to run on the last day of the month.

1 Like