note 119591 added to datetime.construct
| From: | thehesiod at hotmail dot com | Date: | Tue, 12 Jul 2016 23:41:28 +0000 |
| Subject: | note 119591 added to datetime.construct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205988@lists.php.net to get a copy of this message | ||
I'm surprised this hasn't been mentioned, but when constructing a DateTime with just the
year as a string, DateTime will pre-initialize itself with NOW and then replace the year, so if
today is 7/12/2016:
<?php
print((new DateTime('2015'))->modify('+1
day')->format('Y-m-d'));
?>
results in 2016-07-13
----
Server IP: 72.52.91.14
Probable Submitter: 192.169.22.250
----
Manual Page -- http://php.net/manual/en/datetime.construct.php
Edit -- https://master.php.net/note/edit/119591
Del: integrated -- https://master.php.net/note/delete/119591/integrated
Del: useless -- https://master.php.net/note/delete/119591/useless
Del: bad code -- https://master.php.net/note/delete/119591/bad+code
Del: spam -- https://master.php.net/note/delete/119591/spam
Del: non-english -- https://master.php.net/note/delete/119591/non-english
Del: in docs -- https://master.php.net/note/delete/119591/in+docs
Del: other reasons-- https://master.php.net/note/delete/119591
Reject -- https://master.php.net/note/reject/119591
Search -- https://master.php.net/manage/user-notes.php