<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.idate.php',
    1 => 'idate',
    2 => 'Format a local time/date part as integer',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Date/Time Functions',
  ),
  'prev' => 
  array (
    0 => 'function.gmstrftime.php',
    1 => 'gmstrftime',
  ),
  'next' => 
  array (
    0 => 'function.localtime.php',
    1 => 'localtime',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/datetime/functions/idate.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.idate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">idate</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">idate</span> &mdash; <span class="dc-title">Format a local time/date part as integer</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.idate-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>idate</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"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$timestamp</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Returns a number formatted according to the given format string using the
   given integer <code class="parameter">timestamp</code> or the current local time
   if no timestamp is given. In other words, <code class="parameter">timestamp</code>
   is optional and defaults to the value of <span class="function"><a href="function.time.php" class="function">time()</a></span>.
  </p>
  <p class="para">
   Unlike the function <span class="function"><a href="function.date.php" class="function">date()</a></span>, <span class="function"><strong>idate()</strong></span>
   accepts just one char in the <code class="parameter">format</code> parameter.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.idate-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">format</code></dt>
     <dd>
      <p class="para">
       <table class="doctable table">
        <caption><strong>The following characters are recognized in the
        <code class="parameter">format</code> parameter string</strong></caption>
        
         <thead>
          <tr>
           <th><code class="parameter">format</code> character</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><code class="literal">B</code></td>
           <td>Swatch Beat/Internet Time</td>
          </tr>

          <tr>
           <td><code class="literal">d</code></td>
           <td>Day of the month</td>
          </tr>

          <tr>
           <td><code class="literal">h</code></td>
           <td>Hour (12 hour format)</td>
          </tr>

          <tr>
           <td><code class="literal">H</code></td>
           <td>Hour (24 hour format)</td>
          </tr>

          <tr>
           <td><code class="literal">i</code></td>
           <td>Minutes</td>
          </tr>

          <tr>
           <td><code class="literal">I</code> (uppercase i)</td>
           <td>returns <code class="literal">1</code> if DST is activated,
            <code class="literal">0</code> otherwise</td>
          </tr>

          <tr>
           <td><code class="literal">L</code> (uppercase l)</td>
           <td>returns <code class="literal">1</code> for leap year,
            <code class="literal">0</code> otherwise</td>
          </tr>

          <tr>
           <td><code class="literal">m</code></td>
           <td>Month number</td>
          </tr>

          <tr>
           <td><code class="literal">N</code></td>
           <td>ISO-8601 day of the week (<code class="literal">1</code> for Monday
            through <code class="literal">7</code> for Sunday)</td>
          </tr>

          <tr>
           <td><code class="literal">o</code></td>
           <td>ISO-8601 year (4 digits)</td>
          </tr>

          <tr>
           <td><code class="literal">s</code></td>
           <td>Seconds</td>
          </tr>

          <tr>
           <td><code class="literal">t</code></td>
           <td>Days in current month</td>
          </tr>

          <tr>
           <td><code class="literal">U</code></td>
           <td>Seconds since the Unix Epoch - January 1 1970 00:00:00 UTC -
            this is the same as <span class="function"><a href="function.time.php" class="function">time()</a></span></td>
          </tr>

          <tr>
           <td><code class="literal">w</code></td>
           <td>Day of the week (<code class="literal">0</code> on Sunday)</td>
          </tr>

          <tr>
           <td><code class="literal">W</code></td>
           <td>ISO-8601 week number of year, weeks starting on
            Monday</td>
          </tr>

          <tr>
           <td><code class="literal">y</code></td>
           <td>Year (1 or 2 digits - check note below)</td>
          </tr>

          <tr>
           <td><code class="literal">Y</code></td>
           <td>Year (4 digits)</td>
          </tr>

          <tr>
           <td><code class="literal">z</code></td>
           <td>Day of the year</td>
          </tr>

          <tr>
           <td><code class="literal">Z</code></td>
           <td>Timezone offset in seconds</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
    
    
<dt><code class="parameter">timestamp</code></dt><dd><p class="para">
The optional <code class="parameter">timestamp</code> parameter is an
<span class="type"><a href="language.types.integer.php" class="type int">int</a></span> Unix timestamp that defaults to the current
local time if <code class="parameter">timestamp</code> is omitted or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>. In other
words, it defaults to the value of <span class="function"><a href="function.time.php" class="function">time()</a></span>.
</p></dd>
      
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.idate-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> on success,  or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
  <p class="para">
   As <span class="function"><strong>idate()</strong></span> always returns an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> and
   as they can&#039;t start with a &quot;0&quot;, <span class="function"><strong>idate()</strong></span> may return
   fewer digits than you would expect. See the example below.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.idate-errors">
  <h3 class="title">Errors/Exceptions</h3>
   
   <p class="para">
Every call to a date/time function will generate a <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>
if the time zone is not valid. See also <span class="function"><a href="function.date-default-timezone-set.php" class="function">date_default_timezone_set()</a></span></p>
 
 </div>


 <div class="refsect1 changelog" id="refsect1-function.idate-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.2.0</td>
       <td>
        Adds the <code class="literal">N</code> (ISO-8601 day of the week) and
        <code class="literal">o</code> (ISO-8601 year) format characters.
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        <code class="parameter">timestamp</code> is nullable now.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.idate-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>idate()</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 />$timestamp </span><span style="color: #007700">= </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'1st January 2004'</span><span style="color: #007700">); </span><span style="color: #FF8000">// 1072915200<br /><br />// this prints the year in a two digit format<br />// however, as this would start with a "0", it<br />// only prints "4"<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">idate</span><span style="color: #007700">(</span><span style="color: #DD0000">'y'</span><span style="color: #007700">, </span><span style="color: #0000BB">$timestamp</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$timestamp </span><span style="color: #007700">= </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'1st January 2024'</span><span style="color: #007700">); </span><span style="color: #FF8000">// 1704067200<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">idate</span><span style="color: #007700">(</span><span style="color: #DD0000">'y'</span><span style="color: #007700">, </span><span style="color: #0000BB">$timestamp</span><span style="color: #007700">);</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">4
24</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.idate-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="datetime.format.php" class="methodname" rel="rdfs-seeAlso">DateTimeInterface::format()</a> - Returns date formatted according to given format</span></li>
    <li><span class="function"><a href="function.date.php" class="function" rel="rdfs-seeAlso">date()</a> - Format a Unix timestamp</span></li>
    <li><span class="function"><a href="function.getdate.php" class="function" rel="rdfs-seeAlso">getdate()</a> - Get date/time information</span></li>
    <li><span class="function"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - Return current Unix timestamp</span></li>
   </ul>
  </p>
 </div>

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