Is date between (range) function

A

Anonymous

Guest
Is there a function that will return true or false if a date falls between two given dates
eg:
dateisbetween(currentdate, date1, date2)

If there isn't a function that does that, how do I check to see if todays date is greater than a given date and if todays date is less than a given date? Also how would I format the dates.

Here's what I'm trying to do. I want to check if todays date is between the 1st of Dec & the 31st Dec so I can turn on the xmas decorations on my site each year.

Thanks
MaxDax :?
 
MaxDax said:
Is there a function that will return true or false if a date falls between two given dates
eg:
dateisbetween(currentdate, date1, date2)

Did you think, perhaps, of checking the Date and Time functions section of the documentation?

Here's how you might do it:

Code:
<?php
// pass the dates in any format understood by strtotime()
function dateisbetween($currentdate, $date1, $date2) {
   $currentdate = strtotime($currentdate);
   return ($currentdate >= strtotime($date1)) &&
          ($currentdate <= strtotime($date2));
}
?>
 
Back
Top