List dates between specified dates
I recently had the need to list dates between specified dates for an application. I created a function for doing some sort of date lister. I just wanted to share it.
It revolves around the php mktime function. We loop around until we have a date value equal the checked out date.
Anyway, here's the code:
function get_date_list($date_value, $another_date_value)
$check_in_date = strtotime($date_value);
$check_out_date = strtotime($another_date_value);
$increment = 0;
$date_loop = '';
while ($check_out_date != $date_loop)
{
$date_loop = mktime(0, 0, 0, date('n', $check_in_date), date('j', $check_in_date) + $increment, date('Y', $check_in_date));
$reservation_dates[] = $date_loop;
$increment++;
}
return $reservation_dates;
}
It returns an array of timestamps. You could of course simply modify the code to fit your needs.
Categories: How To
Tags: php
No Comments