note 123447 added to datetime.format
| From: | mesa dot fx at gmail dot com | Date: | Mon, 17 Dec 2018 13:21:21 +0000 |
| Subject: | note 123447 added to datetime.format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209916@lists.php.net to get a copy of this message | ||
There is a bit confusing logic may appear using year week number:
<?php
echo (new \DateTime("2018-12-31 13:05:21"))->format("YW") . PHP_EOL;
?>
will output 201801, not 201901 nor 201852, because of strange ISO_8601-2004 standard: the first
calendar week of a year is that one which includes the first Thursday of that year,
so this date (it is Monday) do belong to the first week of 2019 (this is why 'W' format
gives 01), but internal timestamp is of 2018 (and 'Y' format obey this), therefore getting
us unexpected result of 201801. So be careful when using this output with something important (i
know projects where this was used to form MySQL partitions).
----
Server IP: 208.43.231.9
Probable Submitter: 193.201.100.20
----
Manual Page -- http://php.net/manual/en/datetime.format.php
Edit -- https://master.php.net/note/edit/123447
Del: integrated -- https://master.php.net/note/delete/123447/integrated
Del: useless -- https://master.php.net/note/delete/123447/useless
Del: bad code -- https://master.php.net/note/delete/123447/bad+code
Del: spam -- https://master.php.net/note/delete/123447/spam
Del: non-english -- https://master.php.net/note/delete/123447/non-english
Del: in docs -- https://master.php.net/note/delete/123447/in+docs
Del: other reasons-- https://master.php.net/note/delete/123447
Reject -- https://master.php.net/note/reject/123447
Search -- https://master.php.net/manage/user-notes.php