-1

I'm working on a plugin, but I can't get it working.

The code below is supposed to do something when the current date is between 2 chosen dates by the user.

So if date is in between 12-01-2016 ($snow['period_past']) and tomorrow is 12-03-2016 ($snow['period_future']), do something...

$date = date('Y-m-d');
$date = date('Y-m-d', strtotime($date));

$snowStart = date('Y-m-d', strtotime($snow['period_past']));
$snowEnd = date('Y-m-d', strtotime($snow['period_future']));

if (($date > $snowStart) && ($date < $snowEnd)) {
         // do this and that
}

The code above works, but it only works between the dates. How can I make it work so it also works when its at the $snow['period_past'] date and $snow['period_future'] date?

Sorry for my bad explanation, English is not my native language.

Jerrald
  • 19
  • 1
  • 5

2 Answers2

3
if (($date >= $snowStart) && ($date <= $snowEnd)) 
{
     // do this and that
}
Nandan Bhat
  • 1,573
  • 2
  • 9
  • 21
1

You are doing a greater than > or less than < comparison.

To get the condition to meet when the date is equal to $snow['period_past'] or $snow['period_future'], you should have the following comparison in place:

if (($date >= $snowStart) && ($date =< $snowEnd)) 
{
   // your code here
}
coderodour
  • 1,072
  • 8
  • 16