note 120063 added to datetime.formats
| From: | Ray.PaseursometimesusesGmail | Date: | Wed, 19 Oct 2016 15:59:30 +0000 |
| Subject: | note 120063 added to datetime.formats | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206926@lists.php.net to get a copy of this message | ||
When you've got external inputs that do not strictly follow the formatting and disambiguation
rules, you may still be able to use the static method ::createFromFormat() to create a usable
DateTime object
<?php
/**
* Date values separated by slash are assumed to be in American order: m/d/y
* Date values separated by dash are assumed to be in European order: d-m-y
* Exact formats for date/time strings can be injected with ::createFromFormat()
*/
error_reporting(E_ALL);
// THIS IS INVALID, WOULD IMPLY MONTH == 19
$external = "19/10/2016 14:48:21";
// HOWEVER WE CAN INJECT THE FORMATTING WHEN WE DECODE THE DATE
$format = "d/m/Y H:i:s";
$dateobj = DateTime::createFromFormat($format, $external);
$iso_datetime = $dateobj->format(Datetime::ATOM);
echo "SUCCESS: $external EQUALS ISO-8601 $iso_datetime";
// MAN PAGE: http://php.net/manual/en/datetime.createfromformat.php
----
Server IP: 72.52.91.14
Probable Submitter: 98.169.66.145
----
Manual Page -- http://php.net/manual/en/datetime.formats.php
Edit -- https://master.php.net/note/edit/120063
Del: integrated -- https://master.php.net/note/delete/120063/integrated
Del: useless -- https://master.php.net/note/delete/120063/useless
Del: bad code -- https://master.php.net/note/delete/120063/bad+code
Del: spam -- https://master.php.net/note/delete/120063/spam
Del: non-english -- https://master.php.net/note/delete/120063/non-english
Del: in docs -- https://master.php.net/note/delete/120063/in+docs
Del: other reasons-- https://master.php.net/note/delete/120063
Reject -- https://master.php.net/note/reject/120063
Search -- https://master.php.net/manage/user-notes.php