|  | Posted by Ken Robinson on 01/21/06 04:28 
Pedro Graca wrote:> Notgiven wrote:
 > > Say you have two dates, 2005-01-01 and 2005-01-24. I want to get a list or
 > > array or all the date between and including those two dates.
 > >
 > > I want to include this list in a query so I need it in a format like:
 > > '2005-01-01', '2005-01-02',...
 
 Try this simple function:
 
 <?php
 $date_array = date_range('10/20/2005','01/31/2006');
 $dates = "'" . implode("','",$date_array) . "'";
 echo $dates . "<br />\n";
 
 function date_range($sd,$ed)
 {
 $tmp = array()
 $sdu = strtotime($sd);
 $edu = strtotime($ed);
 while ($sdu <= $edu) {
 $tmp[] = date('Y-m-d',$sdu);
 $sdu = strtotime('+1 day',$sdu);
 }
 return ($tmp);
 }
 ?>
 
 Ken
  Navigation: [Reply to this message] |