note 117459 added to function.date-create

From: Date: Fri, 12 Jun 2015 07:36:16 +0000
Subject: note 117459 added to function.date-create
Groups: php.notes 
Request: Send a blank email to php-notes+get-202849@lists.php.net to get a copy of this message
@Marton Bodonyi This is not exactly true. The following code: [code] echo "1\n"; print_r(date_create('13-02-2013')); echo "2\n"; print_r(date_create('13/02/2013')); echo "3\n"; print_r(new DateTime('13-02-2013')); echo "4\n"; print_r(new DateTime('13/02/2013')); [/code] produces the following output: [code] 1 DateTime Object ( [date] => 2013-02-13 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) 2 3 DateTime Object ( [date] => 2013-02-13 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/London ) 4 <br /> <b>Fatal error</b>: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (13/02/2013) at position 0 (1): Unexpected character' in /test.php:23 Stack trace: #0 /test.php(23): DateTime-&gt;__construct('13/02/2013') #1 {main} thrown in <b>/test.php</b> on line <b>23</b><br /> [/code] Which means that only slashes format actually wants you to use American order of date parts. Hence you should use 'dd-mm-yyyy' or 'mm/dd/yyyy' Which is weird, and should not be such. PHP version is 5.4.40 ---- Server IP: 72.52.91.14 Probable Submitter: 138.37.90.1 ---- Manual Page -- http://php.net/manual/en/function.date-create.php Edit -- https://master.php.net/note/edit/117459 Del: integrated -- https://master.php.net/note/delete/117459/integrated Del: useless -- https://master.php.net/note/delete/117459/useless Del: bad code -- https://master.php.net/note/delete/117459/bad+code Del: spam -- https://master.php.net/note/delete/117459/spam Del: non-english -- https://master.php.net/note/delete/117459/non-english Del: in docs -- https://master.php.net/note/delete/117459/in+docs Del: other reasons-- https://master.php.net/note/delete/117459 Reject -- https://master.php.net/note/reject/117459 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202849) next »