Last active
August 29, 2015 14:10
-
-
Save JaisonBrooks/d93a540e5c2e8749ce4b to your computer and use it in GitHub Desktop.
Create array of dates between a start date and end date | 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 get_lastweek_start_date($revered) { | |
$previous_week = strtotime("-1 week +1 day"); | |
$start_week = strtotime("last monday midnight",$previous_week); | |
$end_week = strtotime("next sunday",$start_week); | |
$start_week = date("Y-m-d",$start_week); | |
return $start_week; | |
} | |
function get_lastweek_ending_date() { | |
$previous_week = strtotime("-1 week +1 day"); | |
$start_week = strtotime("last monday midnight",$previous_week); | |
$end_week = strtotime("next sunday",$start_week); | |
$end_week = date("Y-m-d",$end_week); | |
return $end_week; | |
} | |
function createDateRangeArray($strDateFrom,$strDateTo) { | |
// Input two dates in the following formate -> (Y-m-d) and you will be returned an array of dates between the inputs | |
$aryRange=array(); | |
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4)); | |
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4)); | |
if ($iDateTo>=$iDateFrom) { | |
array_push($aryRange,date('m/d/y',$iDateFrom)); // first entry | |
while ($iDateFrom<$iDateTo) { | |
$iDateFrom+=86400; // add 24 hours | |
array_push($aryRange,date('m/d/y',$iDateFrom)); | |
} | |
} | |
return $aryRange; | |
} | |
//Usage | |
$DateRange = createDateRangeArray(get_lastweek_start_date(true), get_lastweek_ending_date(true)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment