Skip to content

Instantly share code, notes, and snippets.

@josephdicdican
Created January 12, 2017 01:51
Show Gist options
  • Save josephdicdican/a0b5488e54897b7ec620213610f4219a to your computer and use it in GitHub Desktop.
Save josephdicdican/a0b5488e54897b7ec620213610f4219a to your computer and use it in GitHub Desktop.
PHP Date Compare
<?php
$dt = strtotime("2017-01-09 08:59:35");
$format = 'Y-m-d'; // format 'j/n/Y' gives wrong output if used for comparing two dates ('Y-m-d' is working)
$date_limit = date($format, strtotime('+0 months', $dt));
$dt_now = date($format);
if($date_limit > $dt_now) {
echo $date_limit . " is greater than " . $dt_now;
} else {
echo $date_limit . " is less than " . $dt_now;
}
echo "\n".date('j/n/Y', strtotime($date_limit));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment