|
-
Oct 26th, 2005, 02:55 PM
#1
Thread Starter
Addicted Member
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?
Last edited by _Yoyo; Oct 26th, 2005 at 03:05 PM.
The biggest man you ever did see was once just a baby.
Bob Marley
-
Oct 26th, 2005, 05:57 PM
#2
Stuck in the 80s
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;
}
?>
-
Oct 27th, 2005, 03:45 PM
#3
Thread Starter
Addicted Member
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?
The biggest man you ever did see was once just a baby.
Bob Marley
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|