Created
November 15, 2020 04:46
-
-
Save remoharsono/de996178ade2dcc354485c364385adea to your computer and use it in GitHub Desktop.
PHP | Get number of days
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 | |
/** | |
* 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