Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Created November 15, 2020 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remoharsono/de996178ade2dcc354485c364385adea to your computer and use it in GitHub Desktop.
Save remoharsono/de996178ade2dcc354485c364385adea to your computer and use it in GitHub Desktop.
PHP | Get number of days
<?php
/**
* Source: https://stackoverflow.com/questions/2040560/finding-the-number-of-days-between-two-dates
* Saksham Gupta
*/
function getNumDays($dateStart, $dateEnd) {
$vDateStart = new DateTime($dateStart);
$vDateEnd = new DateTime($dateEnd);
$diff = $vDateEnd->diff($vDateStart)->format("%a");
return $diff;
}
$dateStart = '2020-11-10';
$dateEnd = '2020-11-20';
echo getNumDays($dateStart, $dateEnd) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment