Open In App

PHP | date_parse_from_format() Function

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:

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
  
// 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
  
// 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:

Reference: http://php.net/manual/en/function.date-parse-from-format.php


Article Tags :