Number of days left until 07.07.07

According to my google analytics account, the most popular google search that brings people to my website is “days left until 07.07.07“. I found this interesting and also quite funny since I only put this information in our wedding section to inform people of the time left before my wedding. Regardless, I thought I could share the script I wrote/edited in order to find the famous countdown.

Of course, there are many other ways to implement this. For example, I could use javascript to update the time every minutes (or seconds) without reloading the page, however I chose a server-side language so that the outcome is independent of the viewer’s setting (Javascript on/off).

<?php
 function countdown($yr, $month, $day, $hr, $min){
 // make a unix timestamp for the given date
 $countdown = mktime($hr, $min, 0, $month, $day, $yr, -1);
 
 // get current unix timestamp
 $today = time();
 
 // get the number of minutes between the times
 $diff = $countdown - $today;
 
 // Make sure the date is not passed already
 if ($diff < 0) $diff = 0;
 
 // Number of Days left
 $days = floor($difference/86400);
 // Number of Hours left
 $hours = floor(($diff - $days*86400)/3600);
 // Number of Minutes left
 $mins = floor(($diff - $days*86400 - $hours*3600)/60);
 
 echo "".$days." days ".$hours." hours ".$mins." minutes";
} ?>

To use the function, you simply call it using

<?php countdown(2007,7,7,14,0); ?>
Facebook Twitter Email