Expected Input:
getDatesFromRange( '2010-10-01', '2010-10-05' );
Expected Output:
Array( '2010-10-01', '2010-10-02', '2010-10-03', '2010-10-04', '2010-10-05' )
Expected Input:
getDatesFromRange( '2010-10-01', '2010-10-05' );
Expected Output:
Array( '2010-10-01', '2010-10-02', '2010-10-03', '2010-10-04', '2010-10-05' )
Simple but like a charm:
Note that the answer provided by ViNce does NOT include the end date for the period.
If you are using PHP 5.3+, your best bet is to use a function like this:
Then, you would call the function as expected:
Run demo
Note about
DatePeriod
class: You can use the 4th parameter of DatePeriod to exclude the start date (DatePeriod::EXCLUDE_START_DATE
) but you cannot, at this time, include the end date.I think it's the shortest answer
Edit the code as you like
many ways of getting this done, but finally it all depends on PHP version you are using. Here is summary of all solutions:
get PHP version:
PHP 5.3+
PHP 4+
PHP < 4
you should upgrade :)
Source: http://boonedocks.net/mike/archives/137-Creating-a-Date-Range-Array-with-PHP.html