YamdaBlam!

PHP Looping through a range of dates

by on Sep.10, 2010, under PHP

Problem:
You need to get the individual dates in a date range and store them in an arbitary data structure such as an array

Solution:

$endDate = date(“Y-m-d”, strtotime(‘yesterday’));
$startDate = ’2010-08-01′;

$newDate = $startDate;
$arRangeOfDates = array();
while($newDate != $endDate) {
$newDate = date(‘Y-m-d’,strtotime(date(“Y-m-d”, strtotime($newDate)) . ” +1 day”));
$arRangeOfDates[]=$newDate;
}

:, ,
No comments for this entry yet...

Leave a Reply

Powered by WP Hashcash

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!