Reputation: 31
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.
Upvotes: 3
Views: 63
Reputation: 4557
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
}
Upvotes: 3