1

I am running this PHP Code:

$earliest='2013-11-19 23:00:00';
$latest='2013-11-19 01:00:00';

if(isset($earliest) and isset($latest))
{
    if(date("Y-m-d H:i:s") >= $earliest and date("Y-m-d H:i:s") <= $latest)
    {
        echo 'yes';
    }
    else
    {
        echo 'no';
    }
}

the current date/time (2013-11-19 12:52:00) is > or = to the $earliest variable but its displaying no

any ideas why this would be? have i done something wrong in my code?

if i do just:

if(date("Y-m-d H:i:s") <= $latest)

it displays yes

2 Answers 2

2

Your earliest is actually after your latest (11pm vs 1am)

Sign up to request clarification or add additional context in comments.

Comments

0

Your comparison operators are incorrect:

 if(date("Y-m-d H:i:s") >= $earliest and date("Y-m-d H:i:s") <= $latest)

should be:

 if(date("Y-m-d H:i:s") >= $earliest && date("Y-m-d H:i:s") <= $latest)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.