Monthly Archive


Friday 13th

As today is Friday 13th with all of the implications that holds – who me superstitious? – I thought I would find out other days of the year I needed to hibernate

function fri13 {
param ($year)
    for ($m=1; $m -le 12; $m++) {
        $d = [datetime]"$m/13/$year"
        if ($d.DayOfWeek -eq "Friday"){

The function takes a year as the parameter and iterates through the months building dates for the 13th of each month. Remember that the date is always mm/dd/yyyy format when creating dates like this.  The date is built using string substitution – that is just so useful.

A check on the day of the week for the date and if is a friday the date is listed out.

The function is called as

fri13 2009 

If you want to check for a number of years then we can use a loop

for ($y=2009; $y -le 2014; $y++) {  fri13 $y}

Just in case you were wondering – these are the days to be aware of

13 February 2009
13 March 2009
13 November 2009
13 August 2010
13 May 2011
13 January 2012
13 April 2012
13 July 2012
13 September 2013
13 December 2013
13 June 2014

Lets be careful out there.


Technorati Tags: PowerShell,dates

Leave a Reply