note 128206 added to datetime.createfromformat

From: Date: Fri, 10 Feb 2023 11:04:01 +0000
Subject: note 128206 added to datetime.createfromformat
Groups: php.notes 
Request: Send a blank email to php-notes+get-220162@lists.php.net to get a copy of this message
Examples: <?php // Year-month-day DateTime::createFromFormat('Y-m-d', '2013-10-14'); // object(DateTime) DateTime::createFromFormat('Y-m-d', '2013-10-14 09:00'); // bool(false) // day-month-Year DateTime::createFromFormat('d-m-Y', '14-10-2013'); // object(DateTime) DateTime::createFromFormat('d-m-Y', '14-10-2013 09:00'); // bool(false) // Unix epoch DateTime::createFromFormat('U', '1381734000'); // object(DateTime) DateTime::createFromFormat('U', '2013-10-14'); // bool(false) DateTime::createFromFormat('U', ''); // bool(false) // The methods below will return an object(DateTime) DateTime::createFromFormat(DateTimeInterface::ISO8601, '2004-02-12T15:19:21+00:00'); DateTime::createFromFormat(DateTimeInterface::COOKIE, 'Monday, 14-Oct-2013 09:00:00 CEST'); DateTime::createFromFormat(DateTimeInterface::RFC822, 'Mon, 14 Oct 13 09:00:00 +0200'); DateTime::createFromFormat(DateTimeInterface::RFC850, 'Monday, 14-Oct-13 09:00:00 CEST'); DateTime::createFromFormat(DateTimeInterface::RFC1036, 'Mon, 14 Oct 13 09:00:00 +0200'); DateTime::createFromFormat(DateTimeInterface::RFC1123, 'Mon, 14 Oct 2013 09:00:00 +0200'); DateTime::createFromFormat(DateTimeInterface::RFC7231, 'Mon, 14 Oct 2013 09:00:00 GMT'); DateTime::createFromFormat(DateTimeInterface::RFC2822, 'Mon, 14 Oct 2013 09:00:00 +0200'); DateTime::createFromFormat(DateTimeInterface::RFC3339, '2013-10-14T09:00:00+02:00'); DateTime::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, '2013-10-14T09:00:00.000+02:00'); DateTime::createFromFormat(DateTimeInterface::RSS, 'Mon, 14 Oct 2013 09:00:00 +0200'); DateTime::createFromFormat(DateTimeInterface::W3C, '2013-10-14T09:00:00+02:00'); ?> Note: the format supplied to DateTime::createFromFormat() differs from the format described in DateTime::format(). Take a look at the examples below: <?php $iso8601date = (new DateTime('2013-10-14'))->format('c'); // string(25) "2013-10-14T00:00:00+00:00" $dateTimeA = DateTime::createFromFormat('c', $iso8601date); // bool(false) $dateTimeB = DateTime::createFromFormat(DateTimeInterface::ISO8601, $iso8601date); // object(DateTime) ?> Thus, the format rules for DateTime::createFromFormat() can be found at DateTimeImmutable::createFromFormat(). Link: https://www.php.net/manual/en/datetimeimmutable.createfromformat.php ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 2a02:58:14d:5100:e8dd:a488:41e:fc7b) ---- Manual Page -- https://php.net/manual/en/datetime.createfromformat.php Edit -- https://main.php.net/note/edit/128206 Del: integrated -- https://main.php.net/note/delete/128206/integrated Del: useless -- https://main.php.net/note/delete/128206/useless Del: bad code -- https://main.php.net/note/delete/128206/bad+code Del: spam -- https://main.php.net/note/delete/128206/spam Del: non-english -- https://main.php.net/note/delete/128206/non-english Del: in docs -- https://main.php.net/note/delete/128206/in+docs Del: other reasons-- https://main.php.net/note/delete/128206 Reject -- https://main.php.net/note/reject/128206 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220162) next »