datetime - how do I subtract 24 hour from date time object in PHP -
i have following code:
$now = date("y-m-d h:m:s"); $date = date("y-m-d h:m:s", strtotime('-24 hours', $now));
however, gives me error:
a non formed numeric value encountered in...
why this?
$date = (new \datetime())->modify('-24 hours');
or
$date = (new \datetime())->modify('-1 day');
(the latter takes account this comment valid point.)
should work fine here. see http://php.net/datetime
$date instance of datetime, real datetime object.
Comments
Post a Comment