Function to return an array of dates...
Hi,
I need a function that'll return an array containing all dates between a range of dates sent as parameters. For example:
$array() = function('20/10/2005','31/01/2005');
echo $array(0) would result: 20/10/2005
echo $array(1) would be 21/10/2005
echo $array(2) would be 22/10/2005, etc.
is it possible?
Re: Function to return an array of dates...
How about something like this?
PHP Code:
<?php
$array = getDatesBetween('10/01/2005','10/31/2005');
for ($i = 0; $i < count($array); $i++) {
echo $array[$i] . '<br />';
}
function getDatesBetween($dateOne, $dateTwo, $format = 'm/d/Y') {
$return = array();
if (strtotime($dateOne) > strtotime($dateTwo)) {
return $return; // return blank array
}
$currDate = $dateOne;
$i = 0;
while ($currDate <= $dateTwo) {
$return[] = $currDate;
$i++;
$currDate = date($format, strtotime($currDate . ' +1 days'));
}
return $return;
}
?>
Re: Function to return an array of dates...
It doesn't work from one year to another. For instance, from 10/27/2005 to 28/01/2005 it'll only return 10/27/2005. Anyone?