Created
May 13, 2017 08:05
-
-
Save adeel-raza/a065a9079c3d51191af73fdda34ee3b1 to your computer and use it in GitHub Desktop.
Compare 2 dates and find the difference in days between them
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 | |
$match_date = \DateTime::createFromFormat("Y-m-d H:i:s", $date_1); | |
$match_date->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison | |
$today = new \DateTime(); // This object represents current date/time | |
$today->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison | |
$diff = $today->diff( $match_date ); | |
$diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval | |
if($diffDays == 0) { | |
// Current Date is same as $date_1 | |
} else if($diffDays <=30) { | |
// Current Date is less than or equal to 30 days as $date_1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment