Created
November 2, 2021 23:55
-
-
Save fahdi/22ee6f87216c40d4043451c49af40caf to your computer and use it in GitHub Desktop.
Calculate days between dates in php
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 | |
| function calculateDaysBetweenDates() { | |
| // set time zone to karachi | |
| date_default_timezone_set('Asia/Karachi'); | |
| $startDate = new DateTime( 'last thursday' ); | |
| $endDate = new DateTime( 'today' ); | |
| $interval = $startDate->diff( $endDate ); | |
| return $interval->format( '%a' ); | |
| } | |
| echo calculateDaysBetweenDates(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment