The documentation about modify()
shows some examples that always contain a space between the number and its unit:
$date->modify('+1 day');
$date->modify('+1 month');
Are the spaces mandatory? Does the calls with +1day
or +1 day
give the same results?
Example:
$now = new DateTimeImmutable();
echo $now->modify('+1day')->format('c');
echo PHP_EOL;
echo $now->modify('+1 day')->format('c');
I tried on 3v4l and it gives the same dates, so it looks like spaces are not mandatory, but I'm interested in knowing how this input format is defined by the PHP language. The Supported Date and Time Formats page doesn't give any detail (1).
(1): it has been fixed since: https://github.com/php/doc-en/issues/2674#issuecomment-1674040916
source https://stackoverflow.com/questions/76875606/are-spaces-mandatory-when-calling-modify-on-a-datetime-or-datetimeimmutable-ob
No comments:
Post a Comment