<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.datetime.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'class.datetimeinterface.php',
    1 => 'DateTimeInterface',
    2 => 'The DateTimeInterface interface',
  ),
  'up' => 
  array (
    0 => 'book.datetime.php',
    1 => 'Date/Time',
  ),
  'prev' => 
  array (
    0 => 'datetimeimmutable.sub.php',
    1 => 'DateTimeImmutable::sub',
  ),
  'next' => 
  array (
    0 => 'datetime.diff.php',
    1 => 'DateTimeInterface::diff',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/datetime/datetimeinterface.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.datetimeinterface.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.datetimeinterface" class="reference">

 <h1 class="title">The DateTimeInterface interface</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p>


  <div class="section" id="datetimeinterface.intro">
   <h2 class="title">Introduction</h2>
   <p class="para">
    <span class="interfacename"><strong class="interfacename">DateTimeInterface</strong></span> was created
    so that parameter, return, or property type declarations may accept either 
    <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> or <span class="classname"><a href="class.datetime.php" class="classname">DateTime</a></span>
    as a value. It is not possible to
    implement this interface with userland classes.
   </p>
   <p class="para">
    Common constants that allow for formatting
    <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> or
    <span class="classname"><a href="class.datetime.php" class="classname">DateTime</a></span> objects through
    <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeImmutable::format()</a></span> and
    <span class="methodname"><a href="datetime.format.php" class="methodname">DateTime::format()</a></span> are also defined on this
    interface.
   </p>
  </div>


  <div class="section" id="datetimeinterface.synopsis">
   <h2 class="title">Interface synopsis</h2>


   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="modifier">interface</span> <strong class="interfacename"><strong class="interfacename">DateTimeInterface</strong></strong> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.atom"><var class="varname">ATOM</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sP&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.cookie"><var class="varname">COOKIE</var></a></var><span class="initializer"> = &quot;l, d-M-Y H:i:s T&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601"><var class="varname">ISO8601</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sO&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601-expanded"><var class="varname">ISO8601_EXPANDED</var></a></var><span class="initializer"> = &quot;X-m-d\\TH:i:sP&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc822"><var class="varname">RFC822</var></a></var><span class="initializer"> = &quot;D, d M y H:i:s O&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc850"><var class="varname">RFC850</var></a></var><span class="initializer"> = &quot;l, d-M-y H:i:s T&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc1036"><var class="varname">RFC1036</var></a></var><span class="initializer"> = &quot;D, d M y H:i:s O&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc1123"><var class="varname">RFC1123</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s O&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc7231"><var class="varname">RFC7231</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s \\G\\M\\T&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc2822"><var class="varname">RFC2822</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s O&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc3339"><var class="varname">RFC3339</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sP&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc3339-extended"><var class="varname">RFC3339_EXTENDED</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:s.vP&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rss"><var class="varname">RSS</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s O&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.w3c"><var class="varname">W3C</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sP&quot;</span>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="datetime.diff.php" class="methodname">diff</a></span>(<span class="methodparam"><span class="type"><a href="class.datetimeinterface.php" class="type DateTimeInterface">DateTimeInterface</a></span> <code class="parameter">$targetObject</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$absolute</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><a href="class.dateinterval.php" class="type DateInterval">DateInterval</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.format.php" class="methodname">format</a></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="type"><a href="language.types.string.php" class="type string">string</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.getoffset.php" class="methodname">getOffset</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.gettimestamp.php" class="methodname">getTimestamp</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.gettimezone.php" class="methodname">getTimezone</a></span>(): <span class="type"><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.serialize.php" class="methodname">__serialize</a></span>(): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.unserialize.php" class="methodname">__unserialize</a></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$data</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="attribute"><a href="class.deprecated.php">#[\Deprecated]</a> </span><br>
   <span class="modifier">public</span> <span class="methodname"><a href="datetime.wakeup.php" class="methodname">__wakeup</a></span>(): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

   }</div>


  </div>


  <div class="section" id="datetimeinterface.constants.types">
   <h2 class="title">Predefined Constants</h2>
   <dl>
    
     <dt id="datetimeinterface.constants.atom">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.atom">DateTimeInterface::ATOM</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-atom">DATE_ATOM</a></code></strong></dt>
     <dd>
      <span class="simpara">
       Atom (example: 2005-08-15T15:52:01+00:00); compatible with ISO-8601, RFC 3339, and XML Schema
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.cookie">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.cookie">DateTimeInterface::COOKIE</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-cookie">DATE_COOKIE</a></code></strong></dt>
     <dd>
      <span class="simpara">
       HTTP Cookies (example: Monday, 15-Aug-2005 15:52:01 UTC)
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.iso8601">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601">DateTimeInterface::ISO8601</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-iso8601">DATE_ISO8601</a></code></strong></dt>
     <dd>
      <span class="simpara">
       ISO-8601-like (example: 2005-08-15T15:52:01+0000)
      </span>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <span class="simpara">
        This format is not compatible with ISO-8601, but is left this way for
        backward compatibility reasons. Use
        <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601-expanded">DateTimeInterface::ISO8601_EXPANDED</a></code></strong>,
        <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.atom">DateTimeInterface::ATOM</a></code></strong> for compatibility with ISO-8601
        instead. (ref ISO8601:2004 section 4.3.3 clause d)
       </span>
      </p></blockquote>
     </dd>
    

    
     <dt id="datetimeinterface.constants.iso8601-expanded">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601-expanded">DateTimeInterface::ISO8601_EXPANDED</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-iso8601-expanded">DATE_ISO8601_EXPANDED</a></code></strong></dt>
     <dd>
      <span class="simpara">
       ISO-8601 Expanded (example: +10191-07-26T08:59:52+01:00)
      </span>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <span class="simpara">
        This format allows for year ranges outside of ISO-8601&#039;s normal range
        of <code class="literal">0000</code>-<code class="literal">9999</code> by always
        including a sign character. It also ensures that the timezone part
        (<code class="literal">+01:00</code>) is compatible with ISO-8601.
       </span>
      </p></blockquote>
     </dd>
    

    
     <dt id="datetimeinterface.constants.rfc822">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc822">DateTimeInterface::RFC822</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rfc822">DATE_RFC822</a></code></strong></dt>
     <dd>
      <span class="simpara">
       RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000)
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.rfc850">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc850">DateTimeInterface::RFC850</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rfc850">DATE_RFC850</a></code></strong></dt>
     <dd>
      <span class="simpara">
       RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC)
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.rfc1036">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc1036">DateTimeInterface::RFC1036</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rfc1036">DATE_RFC1036</a></code></strong></dt>
     <dd>
      <span class="simpara">
       RFC 1036 (example: Mon, 15 Aug 05 15:52:01 +0000)
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.rfc1123">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc1123">DateTimeInterface::RFC1123</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rfc1123">DATE_RFC1123</a></code></strong></dt>
     <dd>
      <span class="simpara">
       RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 +0000)
      </span>
     </dd>
    

    
      <dt id="datetimeinterface.constants.rfc7231">
       <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc7231">DateTimeInterface::RFC7231</a></code></strong>
       <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      </dt>
      <dt><strong><code><a href="datetime.constants.php#constant.date-rfc7231">DATE_RFC7231</a></code></strong></dt>
      <dd>
       <span class="simpara">
        RFC 7231 (since PHP 7.0.19 and 7.1.5) (example: Sat, 30 Apr 2016 17:52:13 GMT)
       </span>
      </dd>
    

    
     <dt id="datetimeinterface.constants.rfc2822">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc2822">DateTimeInterface::RFC2822</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rfc2822">DATE_RFC2822</a></code></strong></dt>
     <dd>
      <span class="simpara">
       RFC 2822 (example: Mon, 15 Aug 2005 15:52:01 +0000)
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.rfc3339">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc3339">DateTimeInterface::RFC3339</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rfc3339">DATE_RFC3339</a></code></strong></dt>
     <dd>
      <span class="simpara">
       Same as <strong><code><a href="datetime.constants.php#constant.date-atom">DATE_ATOM</a></code></strong>
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.rfc3339-extended">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc3339-extended">DateTimeInterface::RFC3339_EXTENDED</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rfc3339-extended">DATE_RFC3339_EXTENDED</a></code></strong></dt>
     <dd>
      <span class="simpara">
       RFC 3339 EXTENDED format (example: 2005-08-15T15:52:01.000+00:00)
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.rss">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rss">DateTimeInterface::RSS</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-rss">DATE_RSS</a></code></strong></dt>
     <dd>
      <span class="simpara">
       RSS (example: Mon, 15 Aug 2005 15:52:01 +0000)
      </span>
     </dd>
    

    
     <dt id="datetimeinterface.constants.w3c">
      <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.w3c">DateTimeInterface::W3C</a></code></strong>
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
     </dt>
     <dt><strong><code><a href="datetime.constants.php#constant.date-w3c">DATE_W3C</a></code></strong></dt>
     <dd>
      <span class="simpara">
       World Wide Web Consortium (example: 2005-08-15T15:52:01+00:00)
      </span>
     </dd>
    

   </dl>
  </div>


  <div class="section" id="datetimeinterface.changelog">
   <h2 class="title">Changelog</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>Version</th>
        <th>Description</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>8.5.0</td>
        <td>
         The <strong><code><a href="datetime.constants.php#constant.date-rfc7231">DATE_RFC7231</a></code></strong> and
         <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc7231">DateTimeInterface::RFC7231</a></code></strong> constants have been deprecated.
        </td>
       </tr>

       <tr>
        <td>8.4.0</td>
        <td>The class constants are now typed.</td>
       </tr>

       <tr>
        <td>8.2.0</td>
        <td>
         The constant <strong><code><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601-expanded">DateTimeInterface::ISO8601_EXPANDED</a></code></strong>
         was added.
        </td>
       </tr>

       <tr>
        <td>7.2.0</td>
        <td>
         The class constants of <span class="classname"><a href="class.datetime.php" class="classname">DateTime</a></span> are now defined
         on <span class="interfacename"><strong class="interfacename">DateTimeInterface</strong></span>.
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

 </div>

 








































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="datetime.diff.php">DateTimeInterface::diff</a> — Returns the difference between two DateTime objects</li><li><a href="datetime.format.php">DateTimeInterface::format</a> — Returns date formatted according to given format</li><li><a href="datetime.getoffset.php">DateTimeInterface::getOffset</a> — Returns the timezone offset</li><li><a href="datetime.gettimestamp.php">DateTimeInterface::getTimestamp</a> — Gets the Unix timestamp</li><li><a href="datetime.gettimezone.php">DateTimeInterface::getTimezone</a> — Return time zone relative to given DateTime</li><li><a href="datetime.serialize.php">DateTime::__serialize</a> — Serialize a DateTime</li><li><a href="datetime.unserialize.php">DateTime::__unserialize</a> — Unserialize an Datetime</li><li><a href="datetime.wakeup.php">DateTime::__wakeup</a> — The __wakeup handler</li></ul>
</div>
<?php manual_footer($setup); ?>