You are here: Re: how do you get a list of all dates between two dates more than a day apart? « PHP Programming Language « IT news, forums, messages
Re: how do you get a list of all dates between two dates more than a day apart?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация