1

I have a $bonus["from_date"] and a $bonus["to_date"], they are in this format: yyyy-mm-dd I would like to check that the todays date is between those two dates.

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

How can i do this?

hakre
  • 184,866
  • 48
  • 414
  • 792
Karem
  • 17,101
  • 71
  • 169
  • 273

2 Answers2

13

Have a look at strtotime()

$from = strtotime($bonus['from_date']);
$to = strtotime($bonus['to_date']);
$now = time();

if($from <= $now && $to >= $now) {
    // It's between
}
Marcus
  • 11,928
  • 5
  • 45
  • 65
  • I could have swore there was a `between` keyword, but I guess I must be thinking of MySQL. Thanks for the help. – James Jan 09 '13 at 22:35
0

You can use standard comparison operators:

if ($today >= $bonus['from_date'] && $today <= $bonus['to_date'])

It works because you are storing as a string with biggest date elements first.

Matthew
  • 46,479
  • 11
  • 85
  • 97