How many times has your pay day fallen on a Monday?

Have you ever wondered how many time your pay day has fallen on a certain day of the week. Especially Mondays as it makes for a long weekend when you are waiting to get paid.

Here is a quick little script that will tell you how many of your paydays in the last 10 years fell on a Monday. Assuming you get paid monthly and on the last day of the month.

Firstly we define the number of months

We now set the count to 0, this will be used to increment the number of paydays that fall on a Monday

Now we need to work through each of the months, based on the number of years we entered,

During our pass through of each month, we need to query if our payday fell on a Monday. We do this by going to the first day of the month at the time 00:00, and subtract 1 second. This gives us the previous day (which would be the last day of the previous month).

Then we use this date to get the day of the week. Now that we have the end of the month in a date format, we can check to see if that day was a Monday, and if so, show the day and date and increase the count by 1

That’s it. You can modify the script as you see fit.  As always feel free to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *