Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

wordpress

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.

like image 757
pacino Avatar asked Dec 01 '25 05:12

pacino


1 Answers

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

}
like image 81
Miroslav Glamuzina Avatar answered Dec 03 '25 21:12

Miroslav Glamuzina



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!