简体   繁体   中英

PHP Operators for Greater/Less than BOTH triggered on same numbers

Trying to add a simple X minute timer to an order status. I'm doing this by setting the timezone, loading the current UNIX time into a variable, then adding X minutes for a trigger time. Every time the page loads, it checks the stored "trigger" time and compares it to the current time. If the current timestamp is larger than the stored one, move on to the next step. The next step happens regardless of the "now" being less than "overtime".

$now = (int) time(); //1550450927
$overtime = strtotime(+5 minutes); //1550451222

//also tried datetime format
$now = new DateTime('now');
$overtime = $now->modify('+10 Minutes');

if ( $now >= $overtime ) { //if "overtime" has passed

 //stuff happens with no regard for reality
 //driving me absolutely bonkers

}

Checking the database inputs of current times compared to requested times, everything is correct with the numbers. They are being stored exactly as the examples given, UNIX timestamps.

Calling modify() is updating the $now value as well as the $overtime value.

Also, this may be of interest to you How do I deep copy a DateTime object?

Try:

$now = (int) time(); //1550450927
$overtime = strtotime("+5 minutes"); //1550451222

//also tried datetime format
$now = new DateTime('now');
$overtime = (new DateTime("now"))->modify("+5 minutes");
print_r($now);
print_r($overtime);
if ( $now >= $overtime ) { //if "overtime" has passed
echo "hit";
 //stuff happens with no regard for reality
 //driving me absolutely bonkers

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM