Saturday, April 14, 2012

Using DayOfWeek in PowerShell

I got a chain letter from my Mom recently that talked about some Feng Shui stuff and the month of July 2012 having 3 Fridays, Saturdays, and Sundays. And that this only happens every 823 years. The email called this something called money bags.

 
July
Sun
Mon
Tue
Wed
Thu
Fri
Sat





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







Based on the pattern, I thought it should actually be much more common than that, but wanted an easy way to see it. So, I figured, I'll use PowerShell to identify the day of the week for July 1 in various years to see which ones were Fridays. They would have the same pattern shown above.

Here is my code:

for ($year=2000;$year -le 2020;$year++){
    [datetime]$date="July 1,$year"
    Write-Host "Year: " $year " July 1 day of week: " $date.dayofweek
    }
As suspected, this pattern seems to show up quite often. And in fact, isn't even happening in 2012. It happened in July 2011. The time previous to that was 2005. It will happen again next in 2016.

Do I have a point here? Not really. It was just fun to use PowerShell to debunk an Internet chain letter.

No comments:

Post a Comment