Generating a Date Range Array in PHP
This short tutorial shows a practical PHP function that builds an array containing every date between a starting date and an ending date. It is handy whenever you need to loop through a continuous span of days, for example in reports, calendars or scheduling logic.
How the function works
The helper create_dates_range_array() accepts a start date and an end date in Y-m-d format. It converts both into Unix timestamps with mktime(), then walks forward one day at a time, pushing each formatted date into the result array until the end date is reached. If the end date comes before the start date, an empty array is returned.
Example usage
After defining the function, simply call it with your two dates and print the result with print_r() to see the full list of dates in the range.
Join the Discussion
Have a question or a better approach? Leave a reply below. Required fields are marked, and your email address will never be published or shared.
Leave a Reply
Recent Posts
Recent Comments
Most Commenting Visitors
My Plugins
My Pages











Tags
counter text texts passing time PHP custom fields categories email quick navigation Blorner outbound links dates




