Created
October 3, 2012 10:37
-
-
Save dvdsmpsn/3826311 to your computer and use it in GitHub Desktop.
PHP Days until Christmas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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