note 123697 added to function.date-create

From: Date: Sat, 16 Mar 2019 11:26:32 +0000
Subject: note 123697 added to function.date-create
Groups: php.notes 
Request: Send a blank email to php-notes+get-210380@lists.php.net to get a copy of this message
Notice php by default assume the give string as such format: '-' is 'y-m-d' '/' is 'm/d/y' Unless the given string has Y or M, that is year is written as full year '2019', or month is written as English shorthand 'Jan', the default assumption will be applied, where the date might be incorrect. The following code show a quick test: (true as of php 7.2) $date = [ '2019-1-3', '19-1-3', '3-1-2019', '3-Jan-19', '3-1-19', //php assume as y-m-d not d-m-y '2019-3-1', '19-3-1', '1-3-2019', '1-3-19', '2019/3/1', '19/3/1', //fail, php think is month 19 '1/3/2019', //php think is m/d/y '1/3/19' ]; //Y-M-d foreach($date as $i => $d){ echo $i ."\r\n"; var_dump(date_format(date_create($d), 'Y-M-d')); echo "\r\n"; } ---- Server IP: 208.43.231.9 Probable Submitter: 82.199.157.34 (proxied: 2001:e68:541a:5526:55f7:4e32:c420:6df8) ---- Manual Page -- http://php.net/manual/en/function.date-create.php Edit -- https://master.php.net/note/edit/123697 Del: integrated -- https://master.php.net/note/delete/123697/integrated Del: useless -- https://master.php.net/note/delete/123697/useless Del: bad code -- https://master.php.net/note/delete/123697/bad+code Del: spam -- https://master.php.net/note/delete/123697/spam Del: non-english -- https://master.php.net/note/delete/123697/non-english Del: in docs -- https://master.php.net/note/delete/123697/in+docs Del: other reasons-- https://master.php.net/note/delete/123697 Reject -- https://master.php.net/note/reject/123697 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#210380) next »