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
  • 193,403
  • 52
  • 435
  • 836
Karem
  • 17,615
  • 72
  • 178
  • 278

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
  • 12,296
  • 5
  • 48
  • 66
  • 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
  • 47,584
  • 11
  • 86
  • 98