Created
January 12, 2017 01:51
-
-
Save josephdicdican/a0b5488e54897b7ec620213610f4219a to your computer and use it in GitHub Desktop.
PHP Date Compare
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 | |
$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