This will not set the time to midnight:
new DateTime('first day of -1 month midnight')
As if midnight
does not exist.
Tested in PHP 7.3.33 and PHP 8.2.4.
The documentation for the time format is not very clear. But even if I take an example directly from it, the behavior will be different:
echo (new DateTime('yesterday noon'))->format('Y-m-d h:m');
Do not output noon, the minute field is non-zero.
I changed the above back to talking about minutes. Can be accessed using i
instead of m
. I tried to correct it, but, as the comments indicate, I did it incorrectly, causing confusion. 12 is indeed the noon of H
and H
. I mean 12 midnight.
h
gives values from 01 to 12H
gives values from 00 to 23, should be used here