date_parse_from_format


php apg

GETS the info about given date formatted according to the specified format.



<?php

arr date_parse_from_format 
str $format str $datetime )


where,

$format Format accepted by DateTime::createFromFormat 

$datetime 
STRING representing the date

?>

 $format 

Format accepted by DateTime::createFromFormat.

format character Description Example parsable values
Day
d and j Day of the month,
2 digits with or without leading zeros
01 to 31 or 1 to 31
D and l A textual representation of a day Mon through Sun or Sunday through Sat or Saturday
S English ordinal suffix for the day of the month,
2 characters.
It's ignored while processing.
st, nd, rd or th.
z The day of the year (starting from 0) 0 through 365
Month
F and M A textual representation of a month, such as January or Sept January through December or Jan through Dec
m and n Numeric representation of a month, with or without leading zeros 01 through 12 or 1 through 12
Year
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
y A two digit representation of a year (which is assumed to be in the range 1970-2069, inclusive) Examples: 99 or 03 (which will be interpreted as 1999 and 2003, respectively)
Time
a and A Ante meridiem and Post meridiem am or pm
g and h 12-hour format of an hour with or without leading zero 1 through 12 or 01 through 12
G and H 24-hour format of an hour with or without leading zeros 0 through 23 or 00 through 23
i Minutes with leading zeros 00 to 59
s Seconds, with leading zeros 00 through 59
u Microseconds (up to six digits) Example: 45, 654321
TimeZone
e, O, P and T TimeZone identifier, or difference to UTC in hours, or difference to UTC with colon between hours and minutes, or TimeZone abbreviation Examples: UTC, GMT, Atlantic/Azores or +0200 or +02:00 or EST, MDT
Full Date/Time
U Seconds since the Unix Epoch
(January 1 1970 00:00:00 GMT)
Example: 1292177455
Whitespace and Separators
(space) One space or one tab Example:
# One of the following separation symbol:
;, :, /, ., ,, -, ( or )
Example: /
;, :, /, ., ,, -, ( or ) The specified character. Example: -
? A random byte Example: ^ (Be aware that for UTF-8 characters you might need more than one ?. In this case, using * is probably what you want instead)
* Random bytes until the next separator or digit Example: * in Y-*-d with the string 2009-aWord-08 will match aWord
! Resets all fields (year, month, day, hour, minute, second, fraction and TimeZone information) to the Unix Epoch Without !, all fields will be set to the current date and time.
| Resets all fields (year, month, day, hour, minute, second, fraction and TimeZone information) to the Unix Epoch if they have not been parsed yet Y-m-d| will set the year, month and day to the information found in the string to parse, and sets the hour, minute and second to 0.
+ If this format specifier is present, trailing data in the string will not cause an error, but a warning instead Use DateTime::getLastErrors to find out whether trailing data was present.
ed48


 $datetime 


STRING representing the date.



 PREDEFINED DATE CONSTANTS 

FORMAT DATES
Usual Interface DateTimeInterface
STRING
DESCRIPTION
DATE_ATOM DateTimeInterface::ATOM
Y-m-d\TH:i:sP
Atom:
2018-08-15T15:52:01+00:00
DATE_COOKIE DateTimeInterface::COOKIE
l, d-M-Y H:i:s T
HTTP Cookies:
Monday, 15-Aug-2018 15:52:01 UTC
* DATE_ISO8601 DateTimeInterface::ISO8601
Y-m-d\TH:i:sO
ISO-8601:
2018-08-15T15:52:01+0000
DATE_RFC822 DateTimeInterface::RFC822
D, d M y H:i:s O
RFC 822:
Mon, 15 Aug 18 15:52:01 +0000
DATE_RFC850 DateTimeInterface::RFC850
l, d-M-y H:i:s T
RFC 850:
Monday, 15-Aug-18 15:52:01 UTC
DATE_RFC1036 DateTimeInterface::RFC1036
D, d M y H:i:s O
RFC 1036:
Mon, 15 Aug 18 15:52:01 +0000
DATE_RFC1123 DateTimeInterface::RFC1123
D, d M Y H:i:s O
RFC 1123:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_RFC2822 DateTimeInterface::RFC2822
D, d M Y H:i:s O
RFC 2822:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_RFC7231 DateTimeInterface::RFC7231
D, d M Y H:i:s \G\M\T
RFC 7231:
Mon, 15 Aug 2018 15:52:01 GMT
DATE_RFC3339 DateTimeInterface::RFC3339
Y-m-d\TH:i:sP
Same as DATE_ATOM
Since PHP 5.1.3
DATE_RFC3339_EXTENDED DateTimeInterface::RFC3339_EXTENDED
Y-m-d\TH:i:s.vP
RFC3339_EXTENDED format
Since PHP 7.0.0
2018-08-15T15:52:01.000+00:00
DATE_RSS DateTimeInterface::RSS
D, d M Y H:i:s O
RSS:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_W3C DateTimeInterface::W3C
Y-m-d\TH:i:sP
World Wide Web Consortium:
2018-08-15T15:52:01+00:00
ed48

* This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons.

Use DATE_ATOM or DateTime::ATOM for compatibility with ISO-8601 instead.


  1 EXERCISE   

<?php

$lang 
'en';

if(
function_exists('date_parse_from_format'))
{

$dateA '08/08/1988 08:08+03:00';

$arrdpA date_parse_from_format("d/m/Y H:iP"$dateA);

foreach(
$arrdpA as $dpA => $dA)
{
    echo 
'[ ' $dpA ' ]';
    echo 
'&nbsp;=&nbsp;';
    
print_r($dA);
    echo 
'<br>';
}

}
else
{
$pt 'Função não definida neste ambiente!<br><br>';
$en 'Function not defined in this environment!<br><br>';
echo $
$lang;
}

?>

  2 EXERCISE   

<?php

$dateB 
'2019-01-24 14:02+03:11';

$arrdpB date_parse_from_format(DateTimeInterface::W3C$dateB);

foreach(
$arrdpB as $dpB => $dB)
{
    echo 
'[ ' $dpB ' ]';
    echo 
'&nbsp;=&nbsp;';
    
print_r($dB);
    echo 
'<br>';
}

/* - - - - - - - - - - - - - - - - - - - - - - -

echo '<pre>';
print_r($arrdpB);
echo '</pre>';

// - - - - - - - - - - - - - - - - - - - - - - -

$errB = date_get_last_errors();

echo '<pre>';
var_dump($errB);
echo '</pre>';

   - - - - - - - - - - - - - - - - - - - - - - - */

?>

  3 EXERCISE   

<?php

date_default_timezone_get
();

$dateC date(DATE_RFC3339_EXTENDED); 

echo 
$dateC '<br><br>';

$arrdpC date_parse_from_format(DateTimeInterface::RFC3339_EXTENDED$dateC);

foreach(
$arrdpC as $dpC => $dC)
{
    echo 
'[ ' $dpC ' ]';
    echo 
'&nbsp;=&nbsp;';
    
print_r($dC);
    echo 
'<br>';
}


?>