I am testing these cases:
$date = new \DateTime();
echo($date->format('Y.m.d')) . PHP_EOL;
$date->setISODate(2018, 1, 1);
echo($date->format('Y.m.d')) . PHP_EOL;
$date->setISODate(2019, 1, 1);
echo($date->format('Y.m.d')) . PHP_EOL;
$date->setISODate(2020, 1, 1);
echo($date->format('Y.m.d')) . PHP_EOL;
Ouput:
2017.08.17
2018.01.01
2018.12.31
2019.12.30
I understood that it would show this:
2017.08.17
2018.01.01
2019.01.01
2020.01.01
Why does that happen?
Surely there is something I did not quite understand.
DateTime::setISODate()
? Its second argument is the week number, not the month. From your expectations I think in fact you are looking forDateTime::setDate()
. – Kopeck