Need to check wether a given date is in between two given dates using PHP, This is the code I’ve written:
$today = date_create('28-Feb-2012');
$fromdate = date_create('20-Feb-2012');
$todate = date_create('22-Feb-2012');
if ($today>=$fromdate && $todat<=$todate)
{
echo 'in range';
}
else
{
echo 'not in range';
}
But this always returns in range. Can’t figure out where the problem is. Please help.
I know it’s a bit of a hacky solution, but I tend to use strtotime() for that kind of thing, as it returns an integer:
EDIT: i assume the
$todatwas just a typo into stackoverflow, and that in your code you actually have$today, but if not that might be your problem – undefined variables, in some settings, can be considered 0 I believe.