Today at work someone pointed out that since the month begins on a Friday this year and it’s a leap year, that this will be a rare February in which we will receive 3 paychecks in one month. The question that had us thinking was how rare this occurrence this actually is. 40 years? or perhaps every 28 years?
To attempt to solve this I figured I’d write a little script to run through the possibilities. Below is a quick script I threw together in PHP.
for ($i=1901; $i<2600; $i++) {
if (date('L', mktime(0, 0, 0, 2, 1, $i))) {
if (date('N', mktime(0, 0, 0, 2, 1, $i)) == 5) {
echo $i . ' is a leap year and the 1st of the month
is a Friday.';
}
}
}
It's pretty basic. It loops through the years 1901 through 2600. Then checks the if the current year that the loop is on happens to be a leap year. If it in fact is then it checks if the first of the February of that year happens to fall on a Friday. Finally if all that criteria is met it prints that year out.
The answer is that it will occur every 28 years.