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

$years = 10
$mths = ($years * 12)

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

$count = 0

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

for($m=1
$m -le $mths
$m++)

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

{$firstofmonth = Get-Date $date -day 1 -hour 0 -minute 0 -second 0
$lastofmonth = (($firstofmonth).AddMonths(-$m).AddSeconds(-1))

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

if ($lastofmonth.DayOfWeek -eq "Monday"){
Write-Host $lastofmonth.DayOfWeek $lastofmonth
$count += 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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.