<?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.date.php',
    1 => 'date',
    2 => 'Format a Unix timestamp',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Date/Time Functions',
  ),
  'prev' => 
  array (
    0 => 'function.checkdate.php',
    1 => 'checkdate',
  ),
  'next' => 
  array (
    0 => 'function.date-add.php',
    1 => 'date_add',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/datetime/functions/date.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.date" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date</span> &mdash; <span class="dc-title">Format a Unix timestamp</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.date-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>date</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"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Returns a string formatted according to the given format string using the
   given integer <code class="parameter">timestamp</code> (Unix timestamp) or the current 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>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    Unix timestamps do not handle timezones. Use the
    <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> class, and its
    <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> formatting method to
    format date/time information with a timezone attached.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">format</code></dt>
    <dd>
     <p class="para">
      Format accepted by <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span>.
     </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <span class="simpara">
        <span class="function"><strong>date()</strong></span> will always generate
        <code class="literal">000000</code> as microseconds since it takes an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>
        parameter, whereas <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> does
        support microseconds if an object of type
        <span class="interfacename"><a href="class.datetimeinterface.php" class="interfacename">DateTimeInterface</a></span> was created with microseconds.
       </span>
      </p></blockquote>
    </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>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a formatted date string.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-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.date-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.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.date-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>date()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// set the default timezone to use.<br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'UTC'</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #FF8000">// Prints something like: Monday<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Prints something like: Monday 8th of August 2005 03:12:46 PM<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l jS \of F Y h:i:s A'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Prints: July 1, 2000 is on a Saturday<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"July 1, 2000 is on a " </span><span style="color: #007700">. </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2000</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* use the constants in the format parameter */<br />// prints something like: Wed, 25 Sep 2013 15:28:57 -0700<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_RFC2822</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// prints something like: 2000-07-01T00:00:00+00:00<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_ATOM</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2000</span><span style="color: #007700">));</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   You can prevent a recognized character in the format string from being
   expanded by escaping it with a preceding backslash. If the character with
   a backslash is already a special sequence, you may need to also escape
   the backslash.
   <div class="example" id="example-2">
    <p><strong>Example #2 Escaping characters in <span class="function"><strong>date()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// prints something like: Wednesday the 15th<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l \t\h\e jS'</span><span style="color: #007700">);</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Some examples of <span class="function"><strong>date()</strong></span> formatting. Note that
   you should escape any other characters, as any which currently
   have a special meaning will produce undesirable results, and
   other characters may be assigned meaning in future PHP versions.
   When escaping, be sure to use single quotes to prevent characters
   like \n from becoming newlines.
   <div class="example" id="example-3">
    <p><strong>Example #3 <span class="function"><strong>date()</strong></span> Formatting</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the<br />// Mountain Standard Time (MST) Time Zone<br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"America/Phoenix"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"F j, Y, g:i a"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                 </span><span style="color: #FF8000">// March 10, 2001, 5:16 pm<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m.d.y"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                         </span><span style="color: #FF8000">// 03.10.01<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"j, n, Y"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                       </span><span style="color: #FF8000">// 10, 3, 2001<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Ymd"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                           </span><span style="color: #FF8000">// 20010310<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'h-i-s, j-m-y, it is w Day'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;     </span><span style="color: #FF8000">// 05-16-18, 10-03-01, 1631 1618 6 Satpm01<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'\i\t \i\s \t\h\e jS \d\a\y.'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;   </span><span style="color: #FF8000">// it is the 10th day.<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D M j G:i:s T Y"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;               </span><span style="color: #FF8000">// Sat Mar 10 17:16:18 MST 2001<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'H:m:s \m \i\s\ \m\o\n\t\h'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;     </span><span style="color: #FF8000">// 17:03:18 m is month<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"H:i:s"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                         </span><span style="color: #FF8000">// 17:16:18<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y-m-d H:i:s"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                   </span><span style="color: #FF8000">// 2001-03-10 17:16:18 (the MySQL DATETIME format)</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   To format dates in other languages,
   <span class="methodname"><a href="intldateformatter.format.php" class="methodname">IntlDateFormatter::format()</a></span>
   can be used instead of <span class="function"><strong>date()</strong></span>.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.date-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    To generate a timestamp from a string representation of the date, you
    may be able to use <span class="function"><a href="function.strtotime.php" class="function">strtotime()</a></span>. Additionally, some
    databases have functions to convert their date formats into timestamps
    (such as MySQL&#039;s <a href="http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html" class="link external">&raquo;&nbsp;UNIX_TIMESTAMP</a>
    function).
   </p>
  </p></blockquote>
  <div class="tip"><strong class="tip">Tip</strong>
   <p class="para">
    Timestamp of the start of the request is available in
    <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['REQUEST_TIME']</a></var>.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="datetimeimmutable.construct.php" class="methodname" rel="rdfs-seeAlso">DateTimeImmutable::__construct()</a> - Returns new DateTimeImmutable object</span></li>
    <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.gmdate.php" class="function" rel="rdfs-seeAlso">gmdate()</a> - Format a GMT/UTC date/time</span></li>
    <li><span class="function"><a href="function.idate.php" class="function" rel="rdfs-seeAlso">idate()</a> - Format a local time/date part as integer</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.getlastmod.php" class="function" rel="rdfs-seeAlso">getlastmod()</a> - Gets time of last page modification</span></li>
    <li><span class="function"><a href="function.mktime.php" class="function" rel="rdfs-seeAlso">mktime()</a> - Get Unix timestamp for a date</span></li>
    <li><span class="methodname"><a href="intldateformatter.format.php" class="methodname" rel="rdfs-seeAlso">IntlDateFormatter::format()</a> - Format the date/time value as a string</span></li>
    <li><span class="function"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - Return current Unix timestamp</span></li>
    <li><a href="class.datetimeinterface.php#datetimeinterface.constants.types" class="link">Predefined DateTime Constants</a></li>
   </ul>
  </p>
 </div>

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