tags:

views:

142

answers:

2

hi

is there any php classes or functions, which will gives us all the days from specific duration? for example, if i want a list of dates from 25/03/2010 (25th march 2010) to 15/05/2010 (15th May 2010), it will give me:

25/03/2010 26/03/2010 26/03/2010 .... .... .... 14/05/2010 15/05/2010

thanks a lot for any help!

+1  A: 
$day1 = strtotime ('25/03/2010');
$day2 = strtotime ('15/05/2010');

$oneday = 60 * 60 * 24;

for ($day = $day1; $day <= $day2; $day + $oneday)
{
    echo date ('Y-m-d', $day);
}

Should do it.

DCD
I would use '25 March 2010' and '15 May 2010' to avoid problems with european/US date format
Eineki
I'd like to beat with a stick whoever though middle-endian dates were a good idea :D
DCD
thanks a lot for the code DCD.. will try it very soon.and I do agree with u on beating anyone who thought middle-endian dates are good idea ;)
imin
hmmm DCD i tried the code but it returns 1970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-011970-01-01197.........................and it almost made my firefox hang...
imin
+2  A: 

It's easy in php5.3 with the new DatePeriod objects:

$begin = new DateTime( '2010-03-25' );
$end = new DateTime( '2010-05-15 23:59:59' );

$period = new DatePeriod($begin, new DateInterval('P1D'), $end);

foreach ( $period as $dt )
  echo $dt->format( "Y-m-d\n " );
Nicolò Martini
my web hosting php is only php 5.2.x.... anyway thanks a lot for the code.. surely will benefit me later
imin