<?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-from-format.php',
    1 => 'date_parse_from_format',
    2 => 'Get info about given date formatted according to the specified format',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Date/Time Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.date-parse.php',
    1 => 'date_parse',
  ),
  'next' => 
  array (
    0 => 'function.date-sub.php',
    1 => 'date_sub',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/datetime/functions/date-parse-from-format.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.date-parse-from-format" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date_parse_from_format</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date_parse_from_format</span> &mdash; <span class="dc-title">Get info about given date formatted according to the specified format</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.date-parse-from-format-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>date_parse_from_format</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</code></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">
   Returns associative array with detailed info about given date/time.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parse-from-format-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">format</code></dt>
     <dd>
      <p class="para">
       Documentation on how the <code class="parameter">format</code> is used, please
       refer to the documentation of
       <span class="function"><a href="datetimeimmutable.createfromformat.php" class="function">DateTimeImmutable::createFromFormat()</a></span>. The same
       rules apply.
      </p>
     </dd>
    
    
     <dt><code class="parameter">datetime</code></dt>
     <dd>
      <p class="para">
       String representing the date/time.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-parse-from-format-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  
  <p class="para">
   Returns associative array with detailed info about given 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">
   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. An example
   below shows such a warning.
  </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. An example
   below shows such an error.
  </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-from-format-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   This functions throws <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> when the
   <code class="parameter">datetime</code> contains NULL-bytes.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.date-parse-from-format-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>8.0.21, 8.1.8, 8.2.0</td>
      <td>
       Now throws <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> when NULL-bytes
       are passed into <code class="parameter">datetime</code>, which previously was silently
       ignored.
      </td>
     </tr>

     <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-from-format-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>date_parse_from_format()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= </span><span style="color: #DD0000">"6.1.2009 13:00+01:00"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">date_parse_from_format</span><span style="color: #007700">(</span><span style="color: #DD0000">"j.n.Y H:iP"</span><span style="color: #007700">, </span><span style="color: #0000BB">$date</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
(
    [year] =&gt; 2009
    [month] =&gt; 1
    [day] =&gt; 6
    [hour] =&gt; 13
    [minute] =&gt; 0
    [second] =&gt; 0
    [fraction] =&gt; 0
    [warning_count] =&gt; 0
    [warnings] =&gt; Array
        (
        )

    [error_count] =&gt; 0
    [errors] =&gt; Array
        (
        )

    [is_localtime] =&gt; 1
    [zone_type] =&gt; 1
    [zone] =&gt; 3600
    [is_dst] =&gt;
)</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 <span class="function"><strong>date_parse_from_format()</strong></span> with warnings example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= </span><span style="color: #DD0000">"26 August 2022 22:30 pm"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$parsed </span><span style="color: #007700">= </span><span style="color: #0000BB">date_parse_from_format</span><span style="color: #007700">(</span><span style="color: #DD0000">"j F Y G:i a"</span><span style="color: #007700">, </span><span style="color: #0000BB">$date</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Warnings count: "</span><span style="color: #007700">, </span><span style="color: #0000BB">$parsed</span><span style="color: #007700">[</span><span style="color: #DD0000">'warning_count'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />foreach (</span><span style="color: #0000BB">$parsed</span><span style="color: #007700">[</span><span style="color: #DD0000">'warnings'</span><span style="color: #007700">] as </span><span style="color: #0000BB">$position </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$message</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"\tOn position </span><span style="color: #007700">{</span><span style="color: #0000BB">$position</span><span style="color: #007700">}</span><span style="color: #DD0000">: </span><span style="color: #007700">{</span><span style="color: #0000BB">$message</span><span style="color: #007700">}</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}</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">Warnings count: 1
	On position 23: The parsed time was invalid</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Example #3 <span class="function"><strong>date_parse_from_format()</strong></span> with errors example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= </span><span style="color: #DD0000">"26 August 2022 CEST"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$parsed </span><span style="color: #007700">= </span><span style="color: #0000BB">date_parse_from_format</span><span style="color: #007700">(</span><span style="color: #DD0000">"j F Y H:i"</span><span style="color: #007700">, </span><span style="color: #0000BB">$date</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Errors count: "</span><span style="color: #007700">, </span><span style="color: #0000BB">$parsed</span><span style="color: #007700">[</span><span style="color: #DD0000">'error_count'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />foreach (</span><span style="color: #0000BB">$parsed</span><span style="color: #007700">[</span><span style="color: #DD0000">'errors'</span><span style="color: #007700">] as </span><span style="color: #0000BB">$position </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$message</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"\tOn position </span><span style="color: #007700">{</span><span style="color: #0000BB">$position</span><span style="color: #007700">}</span><span style="color: #DD0000">: </span><span style="color: #007700">{</span><span style="color: #0000BB">$message</span><span style="color: #007700">}</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />}</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">Errors count: 3
	On position 15: A two digit hour could not be found
	On position 19: Not enough data available to satisfy format</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-parse-from-format-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="datetimeimmutable.createfromformat.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::createFromFormat()</a> - Parses a time string according to a specified format</span></li>
    <li><span class="function"><a href="function.checkdate.php" class="function" rel="rdfs-seeAlso">checkdate()</a> - Valida una data gregoriana</span></li>
   </ul>
  </p>
 </div>

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