<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.datetime.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.date-parse.php',
    1 => 'date_parse',
    2 => 'Returns associative array with detailed info about given date/time',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Date/Time Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.date-offset-get.php',
    1 => 'date_offset_get',
  ),
  'next' => 
  array (
    0 => 'function.date-parse-from-format.php',
    1 => 'date_parse_from_format',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/datetime/functions/date-parse.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.date-parse" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date_parse</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date_parse</span> &mdash; <span class="dc-title">Returns associative array with detailed info about given date/time</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.date-parse-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>date_parse</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$datetime</code></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>date_parse()</strong></span> parses the given
   <code class="parameter">datetime</code> string according to the same rules as
   <span class="function"><a href="function.strtotime.php" class="function">strtotime()</a></span> and
   <span class="function"><a href="datetimeimmutable.construct.php" class="function">DateTimeImmutable::__construct()</a></span>. Instead of returning a
   Unix timestamp (with <span class="function"><a href="function.strtotime.php" class="function">strtotime()</a></span>) or a
   <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> object (with
   <span class="function"><a href="datetimeimmutable.construct.php" class="function">DateTimeImmutable::__construct()</a></span>), it returns an
   associative array with the information that it could detect in the given
   <code class="parameter">datetime</code> string.
  </p>
  <p class="para">
   If no information about a certain group of elements can be found, these
   array elements will be set to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> or are missing. If needed for
   constructing a timestamp or <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> object from
   the same <code class="parameter">datetime</code> string, more fields can be set to
   a non-<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> value. See the examples for cases where that happens.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parse-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">datetime</code></dt>
     <dd>
      <p class="para">
       Date/time in format accepted by
       <span class="function"><a href="datetimeimmutable.construct.php" class="function">DateTimeImmutable::__construct()</a></span>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-parse-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns <span class="type"><a href="language.types.array.php" class="type array">array</a></span> with information about the parsed date/time.
  </p>
  <p class="para">
   The returned array has keys for <code class="literal">year</code>,
   <code class="literal">month</code>, <code class="literal">day</code>, <code class="literal">hour</code>,
   <code class="literal">minute</code>, <code class="literal">second</code>,
   <code class="literal">fraction</code>, and <code class="literal">is_localtime</code>.
  </p>
  <p class="para">
   If <code class="literal">is_localtime</code> is present then
   <code class="literal">zone_type</code> indicates the type of timezone. For type
   <code class="literal">1</code> (UTC offset) the <code class="literal">zone</code>,
   <code class="literal">is_dst</code> fields are added; for type <code class="literal">2</code>
   (abbreviation) the fields <code class="literal">tz_abbr</code>,
   <code class="literal">is_dst</code> are added; and for type <code class="literal">3</code>
   (timezone identifier) the <code class="literal">tz_abbr</code>,
   <code class="literal">tz_id</code> are added.
  </p>
  <p class="para">
   If relative time elements are present in the
   <code class="parameter">datetime</code> string such as <code class="literal">+3 days</code>,
   the then returned array includes a nested array with the key
   <code class="literal">relative</code>. This array then contains the keys
   <code class="literal">year</code>, <code class="literal">month</code>, <code class="literal">day</code>,
   <code class="literal">hour</code>, <code class="literal">minute</code>,
   <code class="literal">second</code>, and if necessary <code class="literal">weekday</code>, and
   <code class="literal">weekdays</code>, depending on the string that was passed in.
  </p>
  <p class="para">
   The array includes <code class="literal">warning_count</code> and
   <code class="literal">warnings</code> fields. The first one indicate how many
   warnings there were.
   The keys of elements <code class="literal">warnings</code> array indicate the
   position in the given <code class="parameter">datetime</code> where the warning
   occurred, with the string value describing the warning itself.
  </p>
  <p class="para">
   The array also contains <code class="literal">error_count</code> and
   <code class="literal">errors</code> fields. The first one indicate how many errors
   were found.
   The keys of elements <code class="literal">errors</code> array indicate the
   position in the given <code class="parameter">datetime</code> where the error
   occurred, with the string value describing the error itself.
  </p>
  <div class="warning"><strong class="warning">Avviso</strong>
   <p class="para">
    The number of array elements in the <code class="literal">warnings</code> and
    <code class="literal">errors</code> arrays might be less than
    <code class="literal">warning_count</code> or <code class="literal">error_count</code> if they
    occurred at the same position.
   </p>
  </div>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-parse-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   In case the date/time format has an error, the element &#039;errors&#039; will
   contain the error messages.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.date-parse-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.2.0</td>
      <td>
       The <code class="literal">zone</code> element of the returned array represents
       seconds instead of minutes now, and its sign is inverted. For instance
       <code class="literal">-120</code> is now <code class="literal">7200</code>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.date-parse-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A <span class="function"><strong>date_parse()</strong></span> example with a comprehensive
    <code class="parameter">datetime</code> string</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_parse</span><span style="color: #007700">(</span><span style="color: #DD0000">"2006-12-12 10:00:00.5"</span><span style="color: #007700">));</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(12) {
  [&quot;year&quot;]=&gt;
  int(2006)
  [&quot;month&quot;]=&gt;
  int(12)
  [&quot;day&quot;]=&gt;
  int(12)
  [&quot;hour&quot;]=&gt;
  int(10)
  [&quot;minute&quot;]=&gt;
  int(0)
  [&quot;second&quot;]=&gt;
  int(0)
  [&quot;fraction&quot;]=&gt;
  float(0.5)
  [&quot;warning_count&quot;]=&gt;
  int(0)
  [&quot;warnings&quot;]=&gt;
  array(0) {
  }
  [&quot;error_count&quot;]=&gt;
  int(0)
  [&quot;errors&quot;]=&gt;
  array(0) {
  }
  [&quot;is_localtime&quot;]=&gt;
  bool(false)
}</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   The timezone elements only show up if they are included in the given
   <code class="parameter">datetime</code> string. In that case there will
   always be a <code class="literal">zone_type</code> element and a few more depending
   on its value.
   <div class="example" id="example-2">
    <p><strong>Example #2 <span class="function"><strong>date_parse()</strong></span> with timezone abbreviation information</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_parse</span><span style="color: #007700">(</span><span style="color: #DD0000">"June 2nd, 2022, 10:28:17 BST"</span><span style="color: #007700">));</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(16) {
  [&quot;year&quot;]=&gt;
  int(2022)
  [&quot;month&quot;]=&gt;
  int(6)
  [&quot;day&quot;]=&gt;
  int(2)
  [&quot;hour&quot;]=&gt;
  int(10)
  [&quot;minute&quot;]=&gt;
  int(28)
  [&quot;second&quot;]=&gt;
  int(17)
  [&quot;fraction&quot;]=&gt;
  float(0)
  [&quot;warning_count&quot;]=&gt;
  int(0)
  [&quot;warnings&quot;]=&gt;
  array(0) {
  }
  [&quot;error_count&quot;]=&gt;
  int(0)
  [&quot;errors&quot;]=&gt;
  array(0) {
  }
  [&quot;is_localtime&quot;]=&gt;
  bool(true)
  [&quot;zone_type&quot;]=&gt;
  int(2)
  [&quot;zone&quot;]=&gt;
  int(0)
  [&quot;is_dst&quot;]=&gt;
  bool(true)
  [&quot;tz_abbr&quot;]=&gt;
  string(3) &quot;BST&quot;
}</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-3">
    <p><strong>Example #3 <span class="function"><strong>date_parse()</strong></span> with timezone identifier information</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_parse</span><span style="color: #007700">(</span><span style="color: #DD0000">"June 2nd, 2022, 10:28:17 Europe/London"</span><span style="color: #007700">));</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(14) {
  [&quot;year&quot;]=&gt;
  int(2022)
  [&quot;month&quot;]=&gt;
  int(6)
  [&quot;day&quot;]=&gt;
  int(2)
  [&quot;hour&quot;]=&gt;
  int(10)
  [&quot;minute&quot;]=&gt;
  int(28)
  [&quot;second&quot;]=&gt;
  int(17)
  [&quot;fraction&quot;]=&gt;
  float(0)
  [&quot;warning_count&quot;]=&gt;
  int(0)
  [&quot;warnings&quot;]=&gt;
  array(0) {
  }
  [&quot;error_count&quot;]=&gt;
  int(0)
  [&quot;errors&quot;]=&gt;
  array(0) {
  }
  [&quot;is_localtime&quot;]=&gt;
  bool(true)
  [&quot;zone_type&quot;]=&gt;
  int(3)
  [&quot;tz_id&quot;]=&gt;
  string(13) &quot;Europe/London&quot;
}</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   If a more minimal <code class="parameter">datetime</code> string is parsed, less
   information is available. In this example, all the time parts are returned
   as <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
   <div class="example" id="example-4">
    <p><strong>Example #4 <span class="function"><strong>date_parse()</strong></span> with a minimal string</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_parse</span><span style="color: #007700">(</span><span style="color: #DD0000">"June 2nd, 2022"</span><span style="color: #007700">));</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(12) {
  [&quot;year&quot;]=&gt;
  int(2022)
  [&quot;month&quot;]=&gt;
  int(6)
  [&quot;day&quot;]=&gt;
  int(2)
  [&quot;hour&quot;]=&gt;
  bool(false)
  [&quot;minute&quot;]=&gt;
  bool(false)
  [&quot;second&quot;]=&gt;
  bool(false)
  [&quot;fraction&quot;]=&gt;
  bool(false)
  [&quot;warning_count&quot;]=&gt;
  int(0)
  [&quot;warnings&quot;]=&gt;
  array(0) {
  }
  [&quot;error_count&quot;]=&gt;
  int(0)
  [&quot;errors&quot;]=&gt;
  array(0) {
  }
  [&quot;is_localtime&quot;]=&gt;
  bool(false)
}</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   <a href="datetime.formats.php#datetime.formats.relative" class="link">Relative formats</a> do not
   influence the values parsed from absolute formats, but are parsed into the
   &quot;relative&quot; element.
   <div class="example" id="example-5">
    <p><strong>Example #5 <span class="function"><strong>date_parse()</strong></span> with relative formats</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_parse</span><span style="color: #007700">(</span><span style="color: #DD0000">"2006-12-12 10:00:00.5 +1 week +1 hour"</span><span style="color: #007700">));</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(13) {
  [&quot;year&quot;]=&gt;
  int(2006)
  [&quot;month&quot;]=&gt;
  int(12)
  [&quot;day&quot;]=&gt;
  int(12)
  [&quot;hour&quot;]=&gt;
  int(10)
  [&quot;minute&quot;]=&gt;
  int(0)
  [&quot;second&quot;]=&gt;
  int(0)
  [&quot;fraction&quot;]=&gt;
  float(0.5)
  [&quot;warning_count&quot;]=&gt;
  int(0)
  [&quot;warnings&quot;]=&gt;
  array(0) {
  }
  [&quot;error_count&quot;]=&gt;
  int(0)
  [&quot;errors&quot;]=&gt;
  array(0) {
  }
  [&quot;is_localtime&quot;]=&gt;
  bool(false)
  [&quot;relative&quot;]=&gt;
  array(6) {
    [&quot;year&quot;]=&gt;
    int(0)
    [&quot;month&quot;]=&gt;
    int(0)
    [&quot;day&quot;]=&gt;
    int(7)
    [&quot;hour&quot;]=&gt;
    int(1)
    [&quot;minute&quot;]=&gt;
    int(0)
    [&quot;second&quot;]=&gt;
    int(0)
  }
}</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   Some stanzas, such as <code class="literal">Thursday</code> will set the time portion
   of the string to <code class="literal">0</code>. If <code class="literal">Thursday</code> is
   passed to <span class="function"><a href="datetimeimmutable.construct.php" class="function">DateTimeImmutable::__construct()</a></span> it would also
   have resulted in the hour, minute, second, and fraction being set to
   <code class="literal">0</code>. In the example below, the year element is however
   left as <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
   <div class="example" id="example-6">
    <p><strong>Example #6 <span class="function"><strong>date_parse()</strong></span> with side-effects</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_parse</span><span style="color: #007700">(</span><span style="color: #DD0000">"Thursday, June 2nd"</span><span style="color: #007700">));</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">array(13) {
  [&quot;year&quot;]=&gt;
  bool(false)
  [&quot;month&quot;]=&gt;
  int(6)
  [&quot;day&quot;]=&gt;
  int(2)
  [&quot;hour&quot;]=&gt;
  int(0)
  [&quot;minute&quot;]=&gt;
  int(0)
  [&quot;second&quot;]=&gt;
  int(0)
  [&quot;fraction&quot;]=&gt;
  float(0)
  [&quot;warning_count&quot;]=&gt;
  int(0)
  [&quot;warnings&quot;]=&gt;
  array(0) {
  }
  [&quot;error_count&quot;]=&gt;
  int(0)
  [&quot;errors&quot;]=&gt;
  array(0) {
  }
  [&quot;is_localtime&quot;]=&gt;
  bool(false)
  [&quot;relative&quot;]=&gt;
  array(7) {
    [&quot;year&quot;]=&gt;
    int(0)
    [&quot;month&quot;]=&gt;
    int(0)
    [&quot;day&quot;]=&gt;
    int(0)
    [&quot;hour&quot;]=&gt;
    int(0)
    [&quot;minute&quot;]=&gt;
    int(0)
    [&quot;second&quot;]=&gt;
    int(0)
    [&quot;weekday&quot;]=&gt;
    int(4)
  }
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-parse-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.date-parse-from-format.php" class="function" rel="rdfs-seeAlso">date_parse_from_format()</a> - Get info about given date formatted according to the specified format</span> for
    parsing a <code class="parameter">datetime</code> with a specific given format</li>
    <li><span class="function"><a href="function.checkdate.php" class="function" rel="rdfs-seeAlso">checkdate()</a> - Valida una data gregoriana</span> for Gregorian date validation</li>
    <li><span class="function"><a href="function.getdate.php" class="function" rel="rdfs-seeAlso">getdate()</a> - Restituisce informazioni sulla data/orario</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>