Skip to content

Instantly share code, notes, and snippets.

@chrismademe
Created May 19, 2021 09:51
Show Gist options
  • Save chrismademe/3c272ce6200379c523fed203e21a5813 to your computer and use it in GitHub Desktop.
Save chrismademe/3c272ce6200379c523fed203e21a5813 to your computer and use it in GitHub Desktop.
PHP: Difference between 2 dates in days
<?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