danielmg
danielmg

Reputation: 211

How to check with PHP that 5 minutes pass from a MySQL TIME column

I'm stuck with this, I'm trying this code with phalcon framework:

if(strtotime("+5 minutes",$quarantine->getFirst()->datecolumnvalue)>time()){...}

But doesn't work, always give false. I cannot do it with just MySQL because PHQL from phalcon doesn't support it, so I just need a PHP comparison. Regards.

Upvotes: 0

Views: 199

Answers (2)

danielmg
danielmg

Reputation: 211

This did the trick :) , just an strtotime missing.

if(strtotime("+5 minutes", strtotime($quarantine->getFirst()->datecolumnvalue))>time()){...}

Upvotes: 1

mopo922
mopo922

Reputation: 6381

Your logic is simply backwards. Just flip > to <:

if (strtotime("+5 minutes",$quarantine->getFirst()->datecolumnvalue) < time()) {
    ...
}

You want cases where, even if you add 5 minutes to the database time, it's still LESS THAN (before) the current time.

Upvotes: 0

Related Questions