Skip to content

Instantly share code, notes, and snippets.

@dvdsmpsn
Created October 3, 2012 10:37
Show Gist options
  • Save dvdsmpsn/3826311 to your computer and use it in GitHub Desktop.
Save dvdsmpsn/3826311 to your computer and use it in GitHub Desktop.
PHP Days until Christmas
<?php
function daysUntilChristmas()
{
$month = 12;
$day = 25;
$year = date("Y");
$yearNext = $year+1;
$days = (int)((mktime (0,0,0,$month,$day,$year) - time())/86400);
if ($days < 0)
{
$year = $year + 1;
$days = (int)((mktime (0,0,0,$month,$day,$year) - time())/86400);
}
$message = "There's only {$days} days until Christmas";
if ($year == $yearNext)
{
$message .= " {$year}";
}
$message .= ".";
return $message;
}
?>
Blimey! <?php echo daysUntilChristmas(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment