downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.idate.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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',
  ),
 
'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',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

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

 </div>

 <a name="function.idate.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><b>idate</b></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$format</tt></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$timestamp</tt><span class="initializer"> = time()</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   Returns a number formatted according to the given format string using the
   given integer <i><tt class="parameter">timestamp</tt></i>
 or the current local time
   if no timestamp is given. In other words, <i><tt class="parameter">timestamp</tt></i>

   is optional and defaults to the value of <a href="function.time.php" class="function">time()</a>.
  </p>
  <p class="para">
   Unlike the function <a href="function.date.php" class="function">date()</a>, <b>idate()</b>
   accepts just one char in the <i><tt class="parameter">format</tt></i>
 parameter.
  </p>
 </div>


 <a name="function.idate.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">format</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       </p><table class="doctable table">
        <caption><b>The following characters are recognized in the
        <i><tt class="parameter">format</tt></i>
 parameter string</b></caption>
       
         <thead valign="middle">
          <tr valign="middle">
           <th><i><tt class="parameter">format</tt></i>
 character</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody valign="middle" class="tbody">
          <tr valign="middle">
           <td align="left"><i>B</i></td>
           <td align="left">Swatch Beat/Internet Time</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>d</i></td>
           <td align="left">Day of the month</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>h</i></td>
           <td align="left">Hour (12 hour format)</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>H</i></td>
           <td align="left">Hour (24 hour format)</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>i</i></td>
           <td align="left">Minutes</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>I</i> (uppercase i)</td>
           <td align="left">returns <i>1</i> if DST is activated,
            <i>0</i> otherwise</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>L</i> (uppercase l)</td>
           <td align="left">returns <i>1</i> for leap year,
            <i>0</i> otherwise</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>m</i></td>
           <td align="left">Month number</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>s</i></td>
           <td align="left">Seconds</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>t</i></td>
           <td align="left">Days in current month</td>
          </tr>

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

          <tr valign="middle">
           <td align="left"><i>w</i></td>
           <td align="left">Day of the week (<i>0</i> on Sunday)</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>W</i></td>
           <td align="left">ISO-8601 week number of year, weeks starting on
            Monday</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>y</i></td>
           <td align="left">Year (1 or 2 digits - check note below)</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>Y</i></td>
           <td align="left">Year (4 digits)</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>z</i></td>
           <td align="left">Day of the year</td>
          </tr>

          <tr valign="middle">
           <td align="left"><i>Z</i></td>
           <td align="left">Timezone offset in seconds</td>
          </tr>

         </tbody>
       
       </table>
<p>
      </p>
     </dd>

   
   
   
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">timestamp</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The optional <i><tt class="parameter">timestamp</tt></i>
 parameter is an
<a href="language.types.integer.php" class="type integer">integer</a> Unix timestamp that defaults to the current
local time if a <i><tt class="parameter">timestamp</tt></i>
 is not given. In other
words, it defaults to the value of <a href="function.time.php" class="function">time()</a>.
</p></dd>

     
   </dl>
<p>
  </p>
 </div>


 <a name="function.idate.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an <a href="language.types.integer.php" class="type integer">integer</a>.
  </p>
  <p class="para">
   As <b>idate()</b> always returns an <a href="language.types.integer.php" class="type integer">integer</a> and
   as they can&#039;t start with a &quot;0&quot;, <b>idate()</b> may return
   fewer digits than you would expect. See the example below.
  </p>
 </div>


 <a name="function.idate.errors"></a><div class="refsect1 errors">
  <h3 class="title">Errors/Exceptions</h3>
  
   <p class="para">
Every call to a date/time function will generate a <b><tt class="constant">E_NOTICE</tt></b>
if the time zone is not valid, and/or a <b><tt class="constant">E_STRICT</tt></b>
or <b><tt class="constant">E_WARNING</tt></b> message
if using the system settings or the <var class="varname">TZ</var> environment
variable. See also <a href="function.date-default-timezone-set.php" class="function">date_default_timezone_set()</a></p>
 
 </div>


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

     </thead>

     <tbody valign="middle" class="tbody">
     
      <tr valign="middle"><td align="left">5.1.0</td><td align="left"><p class="para">
Now issues the <b><tt class="constant">E_STRICT</tt></b> and <b><tt class="constant">E_NOTICE</tt></b>
time zone errors.</p></td></tr>

    
     </tbody>
   
   </table>
<p>
  </p>
 </div>


 <a name="function.idate.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>idate()</b> example</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$timestamp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'1st&nbsp;January&nbsp;2004'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//1072915200<br /><br />//&nbsp;this&nbsp;prints&nbsp;the&nbsp;year&nbsp;in&nbsp;a&nbsp;two&nbsp;digit&nbsp;format<br />//&nbsp;however,&nbsp;as&nbsp;this&nbsp;would&nbsp;start&nbsp;with&nbsp;a&nbsp;"0",&nbsp;it<br />//&nbsp;only&nbsp;prints&nbsp;"4"<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">idate</span><span style="color: #007700">(</span><span style="color: #DD0000">'y'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$timestamp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.idate.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.date.php" class="function" rel="rdfs-seeAlso">date()</a> - Format a local time/date</li>
    <li class="member"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - Return current Unix timestamp</li>
   </ul><p>
  </p>
 </div>

</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites