Subtracting time from variable in PHP
I have a variable last_start which is part of an array in $u
.
I would like to subtract 20 seconds from last_start variable in my PHP code.
private function _process_url(Employ $e, url $u, $job_order, array $urls_processed)
$summary = [
'url_id' => $u->get_id(),
'start_time' => date('Y-m-d H:i:s'),
'success_count' => 0,
'error_count' => 0
];
$u->last_start = new DateTime();
$u->update(['last_start']);
I have a question on this code part:
$u->last_start = new DateTime();
$u->update(['last_start']};
I have tried subtracting 20 seconds from last_start variable nut apparently it is incorrect this way. It does not work. as it gives an error:
Uncaught exception: Call to undefined function modify()
How to fix this?
$u->last_start = new DateTime();
$u->last_start = modify("-20 second");
$u->update(['last_start']};
Answer
Solution:
All that was needed was:
$u->last_start = new DateTime();
$u->last_start = new DateTime('-20 sec');
$u->update(['last_start']);
Source