Last active
August 29, 2015 14:11
-
-
Save RobertCalise/19f3fbaad1d6f8cae2d9 to your computer and use it in GitHub Desktop.
Quick (hacky) way to ensure a PHP date is in the future.
This file contains hidden or 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 | |
// Assuming the date you're looking for is January 2: | |
$when = 'January 2'; | |
// Verbose method: | |
if(($date = strtotime($when)) < time()) { | |
$date = strtotime('+1 year', $date); | |
} | |
// If you need this as a one-liner... | |
$date = (strtotime($when) < time()) ? strtotime('+1 year', strtotime($when)) : strtotime($when); | |
echo date('m/d/Y', $date); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment