Computer >> Computer tutorials >  >> Programming >> PHP

date_parse() function in PHP


The date_parse() function returns associative array with detailed info about given date.

Syntax

date_parse(date)

Parameters

  • date − Specifies date.

Return

The date_parse() function returns associative array with detailed info about given date.

Example

The following is an example −

<?php
   print_r(date_parse("2017-11-08 11:10:40.5"));
?>

Output

The following is the output −

Array
(
   [year] => 2017
   [month] => 11
   [day] => 8
   [hour] => 11
   [minute] => 10
   [second] => 40
   [fraction] => 0.5
   [warning_count] => 0
   [warnings] => Array
   (
   )

   [error_count] => 0
   [errors] => Array
   (
   )

   [is_localtime] =>
)

Example

Let us see another example −

<?php
   print_r(date_parse("2017-10-10 11:00:00.5 +2 week +2 hour"));
?>

Output

The following is the output −

Array
(
   [year] => 2017
   [month] => 10
   [day] => 10
   [hour] => 11
   [minute] => 0
   [second] => 0
   [fraction] => 0.5
   [warning_count] => 0
   [warnings] => Array
   (
   )
   [error_count] => 0
   [errors] => Array
   (
   )
   [is_localtime] =>
   [relative] => Array
   (
     [year] => 0
      [month] => 0
      [day] => 14
      [hour] => 2
      [minute] => 0
      [second] => 0
   )
)