PHP | date_parse_from_format() Function Last Updated : 04 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. Syntax: 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. Day: 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) Month: 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 Year: 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) Time: 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) 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 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. php <?php // Declare and initialize date variable. $date = "0.9.2018 5:00+01:00"; // Function is used to return the detail about date. print_r(date_parse_from_format("j.n.Y H:iP", $date)); ?> Output: Array ( [year] => 2018 [month] => 9 [day] => 0 [hour] => 5 [minute] => 0 [second] => 0 [fraction] => [warning_count] => 1 [warnings] => Array ( [19] => The parsed date was invalid ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => 1 [zone_type] => 1 [zone] => -60 [is_dst] => ) Program 2: php <?php // Declare and initialize date variable. $date = "2015.0.9"; // Function is used to return the detail about date. print_r(date_parse_from_format("Y.z.n", $date)); ?> Output: Array ( [year] => 2015 [month] => 9 [day] => 1 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) Related Article: PHP | date_sun_info() Function PHP | date_sunset() Function PHP | date_parse() Function Reference: http://php.net/manual/en/function.date-parse-from-format.php Comment More infoAdvertise with us Next Article PHP | easter_date() Function V vijay_raj Follow Improve Article Tags : Misc Web Technologies PHP PHP-date-time PHP-function +1 More Practice Tags : Misc Similar Reads PHP | date_create_from_format() Function The date_create_from_format() is an inbuilt function in php which is used to parses a time string according to a specified format. This function accepts three parameters and returns new DateTime in success or false on failure. Syntax: Procedural style date_create_from_format ( $format, $time, $timez 3 min read PHP | date_parse() Function The date_parse() is an inbuilt function in PHP which is used to find the detailed information about a specified date. This function returns an associative array of detailed information for a specified date on success and returns FALSE on failure Syntax: date_parse($date) Parameters Used: The date_pa 2 min read PHP | date_create_immutable_from_format() Function The date_create_immutable_from_format() function is an inbuilt function in PHP which is used to parse a time string according to the specified format. Syntax: Object oriented style: DateTimeImmutable static DateTime::createFromFormat( string $format, string $time, DateTimeZone $timezone )Procedural 2 min read PHP | DateTime format() Function The DateTime::format() function is an inbuilt function in PHP which is used to return the new formatted date according to the specified format. Syntax: Object oriented style string DateTime::format( string $format ) or string DateTimeImmutable::format( string $format ) or string DateTimeInterface::f 1 min read PHP | easter_date() Function The easter_date() function is a built-in function in PHP which returns the Easter date in the year passed as an argument. The current year is taken as default year when no arguments are passed as parameter. Syntax: easter_date( $year ) Parameter: The function accepts one optional parameter $year whi 2 min read Moment.js Parse Date Format Plugin Parse Date Format is a moment.js plugin to can be used to extract a date/time string's format from a given string. This format can then be later used with other Moment methods. Write the below command in the terminal to install Date Format Plugin: npm install moment-parseformat The following are so 1 min read Like