php date list for specified duration
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 开发者_Go百科any help!
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 " );
$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.
精彩评论