Home     Articles & Projects     Products & Web Services     Forum

Count how many Friday the 13th

Hi I was wondering if there is any PHP code that I could use, to show how many friday the 13th there are in 2009 or any year a user request?

I know that sounds strange but no search engine shows this information, and I would like to know. Me and my house mate had a argument over how is correct. I say 3 and he says it only happens once.

I guess I could go though each month but would be better if there was away PHP date would be able to tell me.

Hi Russell, Try something

Hi Russell,

Try something like:

<?php
  $Friday13ths
= 0;
 
$d = strtotime("2009-01-01");
  for(
$i=1;$i<=365;$i++)
  {
    if ((
date("j",$d)==13) && (date("w",$d)==5)) $Friday13ths++;
   
$d += 86400;
  }
  print
$Friday13ths;
?>

:)