Dates between start and end

Hi guys

How can I get a list of dates between

$start=‘22-09-2008’;

$end=‘30-09-2008’;

Regards

Chris

Heres one way, I was surprised that strtotime correctly spotted UK dates though - I’d test that a bit more before using it - else explode the $start and $end and reassemble into normal mm-dd-yyyy dates.


$start='22-09-2008'; 
$end = '30-09-2008' ;
$result = 0 ;
while ( $result != $end ){
$result = date( 'd-m-Y',  strtotime($start .'+1 day' ) );
$arr[] = $result ;
$start = $result ;

}

var_dump ( $arr );

// gives:

array
  0 => string '23-09-2008' (length=10)
  1 => string '24-09-2008' (length=10)
  2 => string '25-09-2008' (length=10)
  3 => string '26-09-2008' (length=10)
  4 => string '27-09-2008' (length=10)
  5 => string '28-09-2008' (length=10)
  6 => string '29-09-2008' (length=10)
  7 => string '30-09-2008' (length=10)

Might be worth experimenting with range.

I didn’t test this, but it’s a start.

<?php
$dates = range(strtotime($start), strtotime($end), 86400);
?>

Good one Joebert!! :tup:

Here is obvious next step:


$start = '22-09-2008';
$end = '30-09-2008';
$dates = range(strtotime($start), strtotime($end), 86400);
foreach($dates as $date)
	echo date('Y-m-d', $date) . '<br />';