Last active
July 20, 2018 13:28
-
-
Save ParryPatel021/0045f7eb0c1bf9e17a13dfbe052583a5 to your computer and use it in GitHub Desktop.
Retrieve Date range from start date to end date in an Array format.
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 | |
//Function calling | |
$dateRange=getDatesFromRange("2018-07-20", "2018-08-05", $format = 'Y-m-d') | |
//Function body | |
private function getDatesFromRange($start, $end, $format = 'Y-m-d') | |
{ | |
$array = array(); | |
$interval = new DateInterval('P1D'); | |
$realEnd = new DateTime($end); | |
$realEnd->add($interval); | |
$period = new DatePeriod(new DateTime($start), $interval, $realEnd); | |
foreach ($period as $date) { | |
$array[] = $date->format($format); | |
} | |
return $array; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment