Proving Leap Year is NOT Every Four Years with PowerShell

Last week, I saw a couple of tweets from PowerShell MVP Jeffery Hicks about leap year that caught my attention:

030614-1

One of the reasons that I found those tweets so interesting is that I had just heard the night before on of all places, Wheel of Fortune, that leap year wasn’t every four years. I’d always been told that leap year was every four years and it has been for my entire life so it was time to investigate further.

I decided to start with one of Jeff’s examples and add some code to it to determine which years should be leap years but weren’t based on the popular belief that leap year is every four years:

030614-2b

Now that’s interesting. Why aren’t those years, shown in the previous example, leap years? I found a Wikipedia article about leap year with the answer to that question which I documented in the description section of the comments in the function shown in the following example. That Wikipedia article also provided some pseudo-code which I converted into PowerShell:

030614-3a

As you can see 1900 was not a leap year and there were 8 years between leap years from 1896 to 1904. Eight years between leap years won’t occur again until years 2096 to 2104 .

µ

2 Comments

  1. Greg Wojan

    Use the Framework Luke… 😉

    1890..1910 | % { “Leap year ($_): $([DateTime]::IsLeapYear($_))” }

    Reply
  2. Greg Wojan

    Actually, I guess I should have paid more attention to Jeff’s second tweet… 🙁 Sigh.

    Reply

Leave a Reply

%d bloggers like this: