Created
May 19, 2021 09:51
-
-
Save chrismademe/3c272ce6200379c523fed203e21a5813 to your computer and use it in GitHub Desktop.
PHP: Difference between 2 dates in days
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 | |
/** | |
* Date diff in days | |
* The difference in days between 2 dates | |
* | |
* @param $from string Y-m-d date string | |
* @param $to string Y-m-d date string | |
*/ | |
function date_diff_in_days($from, $to) { | |
// Setup date objects | |
$now = new DateTime($from); | |
$date = new DateTime($to); | |
return $date->diff($now)->format('%d'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment