The date_parse_from_format() is an inbuilt function in PHP which is used to get information about given date formatted according to the specified format. The date_parse_from_format() function accepts two parameters and returns associative array with detailed information about given date.
array date_parse_from_format ( $format, $date )
Parameters: This function accepts two parameters as mentioned above and described below:
- $format: It is a required parameters which is used to specify the date format. The following parameters string are used in format.
- d and j: It represents the day of the month, 2 digits with or without leading zeros.
- D and l: A textual representation of a day.
- S: English ordinal suffix for the day of the month, 2 characters. It’s ignored while processing.
- z: The day of the year (starting from 0)
- F and M: A textual representation of a month, such as January or Sept
- m and n: Numeric representation of a month, with or without leading zeros
- Y: A full numeric representation of a year, 4 digits
- y: A two digit representation of a year (which is assumed to be in the range 1970-2069, inclusive)
- a and A: Ante meridiem and Post meridiem
- g and h: 12-hour format of an hour with or without leading zero
- G and H: 24-hour format of an hour with or without leading zeros
- i: Minutes with leading zeros
- s: Seconds, with leading zeros
- u: Microseconds (up to six digits)
- 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
- Full Date/Time:
- U: Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
- Whitespace and Separators:
- (space): One space or one tab
- #: One of the following separation symbol: ;, :, /, .,,, -, ( or )
- ;, :, /, .,,, -, ( or ): The specified character.
- ?: A random byte
- *: Random bytes until the next separator or digit
- !: Resets all fields (year, month, day, hour, minute, second, fraction and timezone information) to the Unix Epoch
- |: Resets all fields (year, month, day, hour, minute, second, fraction and timezone information) to the Unix Epoch if they have not been parsed yet
- +: If this format specifier is present, trailing data in the string will not cause an error, but a warning instead
- $date: This is the mandatory parameter which is used to representing the date.
Return Value: This function returns an array containing the detail description about date.
Below programs illustrate the date_parse_from_format() function in PHP.
Array ( [year] => 2018 [month] => 9 [day] => 0 [hour] => 5 [minute] => 0 [second] => 0 [fraction] => [warning_count] => 1 [warnings] => Array (  => The parsed date was invalid ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => 1 [zone_type] => 1 [zone] => -60 [is_dst] => )
Array ( [year] => 2015 [month] => 9 [day] => 1 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => )
- How to get the function name inside a function in PHP ?
- D3.js | d3.hsl() Function
- D3.js | d3.sum() function
- PHP | exp() Function
- PHP | Ds\Map xor() Function
- PHP | cos( ) Function
- PHP | sin( ) Function
- PHP | tan( ) Function
- PHP | Ds\Map put() Function
- D3.js | d3.max() function
- PHP | pi( ) Function
- D3.js | d3.set.has() Function
- PHP | next() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.