Skip to content

Instantly share code, notes, and snippets.

@RobertCalise
Last active August 29, 2015 14:11
Show Gist options
  • Save RobertCalise/19f3fbaad1d6f8cae2d9 to your computer and use it in GitHub Desktop.
Save RobertCalise/19f3fbaad1d6f8cae2d9 to your computer and use it in GitHub Desktop.
Quick (hacky) way to ensure a PHP date is in the future.
<?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