Karem
Karem

Reputation: 18103

If the date is between these two dates then

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?

Upvotes: 1

Views: 10651

Answers (2)

Marcus
Marcus

Reputation: 12586

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
}

Upvotes: 13

Matthew
Matthew

Reputation: 48284

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.

Upvotes: 0

Related Questions