Himmators
Himmators

Reputation: 15006

How come my time-value comparison is not working properly?

if (
    isset($get['when'])
    && !empty($get['when'])
    && !strtotime($get['when'])
    && strtotime($get['when']) < time()
)

Renders false for forexample strtotime($get['when']) = 2010-12-06, this is less than time() ofc.

If I remove && !empty($get['when']) it works fine. Any suggestions why?

Upvotes: 0

Views: 75

Answers (2)

jeroen
jeroen

Reputation: 91734

Your problem is !strtotime($get['when']). strtotime only returns false on failure and all other values are considered true so your statement is always false. I think you want:

(strtotime($get['when']) !== false)

Upvotes: 1

tmg
tmg

Reputation: 872

This is realy interesting part of code green

&& !strtotime($get['when'])  && strtotime($get['when'])

Upvotes: 1

Related Questions