Created
July 27, 2016 10:26
-
-
Save amilabandara/81ed8596a6263ad359d0437db730fa5d to your computer and use it in GitHub Desktop.
Time specific php code snippets
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 | |
//get difference between two dates in days | |
//$now = time(); // or your date as well | |
$now = strtotime("2016-07-28"); | |
$your_date = strtotime("2016-07-26"); | |
$datediff = $now - $your_date; | |
echo floor($datediff/(60*60*24)); | |
//check from date is after than to date | |
//1 use above code check if the echo value is - | |
//or use bellow code | |
if (new DateTime($from_date) > new DateTime($to_date)) { | |
array_push($errors, 'Start date and end date Invalid'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment