You should do:
$datetime_from = date("Y-m-d H:i", strtotime("-45 minutes", strtotime($thestime)));
Having H
instead of h
means a 24-hour format is used, representing the hour with leading zeros: 00
through 23
.
You can read more on this in the PHP date function documentation.
There are also object oriented ways of doing this which are more fluent, like DateTime::sub
:
$datetime_from = (new DateTime($thestime))->sub(DateInterval::createFromDateString('45 minutes'))->format('Y-m-d H:i')
Or the even more expressive way offered by the Carbon
library which extends PHP's built in DateTime
class:
$datetime_from = (new Carbon($thestime))->subMinutes(45)->format('Y-m-d H:i');