Reply to Re: generating a list of dates

Your name:

Reply:


Posted by Carl Vondrick on 01/29/07 06:14

Should do it. Uses unix time stamps.

<?php
function generate_dates($start, $end)
{
$start = strtotime($start);
$end = strtotime($end);

$oneday = 86400;

$return = array();

for ($current = $start; $current <= $end; $current+=$oneday)
{
$return[] = $current;
}

return $return;
}

print '<pre>'; print_r(generate_dates('jan 1, 2005','today'));
?>



> Hi,
>
> Using PHP 4.4.4, I want to generate an array that contains strings
> representing days from Jan. 1, 2005 to whatever the current day is.
> So the array would contain the first values
>
> '2005-01-01', '2005-01-02', '2005-01-03'
>
> and end with the values
>
> '2007-01-27', '2007-01-28'
>
> In case you're interested, I will then take this array and populate a
> MySQL table.
>
> Thanks for any advice, - Dave

--
Carl Vondrick
www.CarlSoft.net

[Back to original 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

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