Skip to content

Instantly share code, notes, and snippets.

@amilabandara
Created July 27, 2016 10:26
Show Gist options
  • Save amilabandara/81ed8596a6263ad359d0437db730fa5d to your computer and use it in GitHub Desktop.
Save amilabandara/81ed8596a6263ad359d0437db730fa5d to your computer and use it in GitHub Desktop.
Time specific php code snippets
<?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