I have an array structured like this:
Array ( [0] => 24-12-2013 [1] => 25-12-2013 [2] => 26-12-2014 [3] => 27-12-2013 [4])
I would like to check if any of the dates in the array are within a given date range.
The date range is structured like this:
$start = (date("d-m-Y", strtotime('25-12-2013')));
$end = (date("d-m-Y", strtotime('26'12'2013')));
I would like to know which dates in the array are within the date range.
Couple things:
DateTime
objects to compare dates, not stringsThis code will do what you want:
See it in action:
http://3v4l.org/GWJI2
Loop over the array turning each date into unix time (seconds since Jan 1, 1970), and do simple math to see if the number of seconds is between the range. Like so:
See it in action