PHP: Get all of the dates between two dates
July 24, 2008 – 10:24 amI'm having trouble explaining this...
This function returns an array of all of the days between two dates. EG: Give it 2008-07-23 and 2008-07-25, and it will return an array containing, 2008-07-23, 2008-07-24, and 2008-07-25.
If you give it an interval, like years, it will give you an array of dates, on per year, between the two dates you specify.
// An array of days between two days, intervals is days, weeks, months, years function get_days($start, $end, $interval = 'days') { $days[] = $start; $current = $start; while($current < $end){ $current = gmdate("Y-m-d", strtotime("+1 $interval", strtotime($current))); $days[] = $current; } return $days; }
