Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2501

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Format a local time/date</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.date-timezone-set.html">date_timezone_set</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.getdate.html">getdate</a></div>
 <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.date" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">date</span> &mdash; <span class="dc-title">Format a local time/date</span></p>

 </div>
  
 <div class="refsect1 description" id="refsect1-function.date-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>date</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code><span class="initializer"> = time()</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   Returns a string formatted according to the given format string using the
   given integer <em><code class="parameter">timestamp</code></em> or the current time
   if no timestamp is given.  In other words, <em><code class="parameter">timestamp</code></em>
   is optional and defaults to the value of  <span class="function"><a href="function.time.html" class="function">time()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">format</code></em></span>
     <dd>

      <p class="para">
       The format of the outputted date <span class="type"><a href="language.types.string.html" class="type string">string</a></span>. See the formatting
       options below. There are also several
       <a href="class.datetime.html#datetime.constants.types" class="link">predefined date constants</a>
       that may be used instead, so for example <strong><code>DATE_RSS</code></strong>
       contains the format string <em>&#039;D, d M Y H:i:s&#039;</em>.
      </p>
      <p class="para">
       <table class="doctable table">
        <caption><strong>The following characters are recognized in the
        <em><code class="parameter">format</code></em> parameter string</strong></caption>
        
         <thead>
          <tr>
           <th><em><code class="parameter">format</code></em> character</th>
           <th>Description</th>
           <th>Example returned values</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td style="text-align: center;"><em class="emphasis">Day</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>d</em></td>
           <td>Day of the month, 2 digits with leading zeros</td>
           <td><em>01</em> to <em>31</em></td>
          </tr>

          <tr>
           <td><em>D</em></td>
           <td>A textual representation of a day, three letters</td>
           <td><em>Mon</em> through <em>Sun</em></td>
          </tr>

          <tr>
           <td><em>j</em></td>
           <td>Day of the month without leading zeros</td>
           <td><em>1</em> to <em>31</em></td>
          </tr>

          <tr>
           <td><em>l</em> (lowercase &#039;L&#039;)</td>
           <td>A full textual representation of the day of the week</td>
           <td><em>Sunday</em> through <em>Saturday</em></td>
          </tr>

          <tr>
           <td><em>N</em></td>
           <td>ISO-8601 numeric representation of the day of the week (added in
           PHP 5.1.0)</td>
           <td><em>1</em> (for Monday) through <em>7</em> (for Sunday)</td>
          </tr>

          <tr>
           <td><em>S</em></td>
           <td>English ordinal suffix for the day of the month, 2 characters</td>
           <td>
            <em>st</em>, <em>nd</em>, <em>rd</em> or
            <em>th</em>.  Works well with <em>j</em>
           </td>
          </tr>

          <tr>
           <td><em>w</em></td>
           <td>Numeric representation of the day of the week</td>
           <td><em>0</em> (for Sunday) through <em>6</em> (for Saturday)</td>
          </tr>

          <tr>
           <td><em>z</em></td>
           <td>The day of the year (starting from 0)</td>
           <td><em>0</em> through <em>365</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Week</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>W</em></td>
           <td>ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)</td>
           <td>Example: <em>42</em> (the 42nd week in the year)</td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Month</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>F</em></td>
           <td>A full textual representation of a month, such as January or March</td>
           <td><em>January</em> through <em>December</em></td>
          </tr>

          <tr>
           <td><em>m</em></td>
           <td>Numeric representation of a month, with leading zeros</td>
           <td><em>01</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>M</em></td>
           <td>A short textual representation of a month, three letters</td>
           <td><em>Jan</em> through <em>Dec</em></td>
          </tr>

          <tr>
           <td><em>n</em></td>
           <td>Numeric representation of a month, without leading zeros</td>
           <td><em>1</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>t</em></td>
           <td>Number of days in the given month</td>
           <td><em>28</em> through <em>31</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Year</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>L</em></td>
           <td>Whether it&#039;s a leap year</td>
           <td><em>1</em> if it is a leap year, <em>0</em> otherwise.</td>
          </tr>

          <tr>
           <td><em>o</em></td>
           <td>ISO-8601 year number. This has the same value as
            <em>Y</em>, except that if the ISO week number
            (<em>W</em>) belongs to the previous or next year, that year
            is used instead. (added in PHP 5.1.0)</td>
           <td>Examples: <em>1999</em> or <em>2003</em></td>
          </tr>

          <tr>
           <td><em>Y</em></td>
           <td>A full numeric representation of a year, 4 digits</td>
           <td>Examples: <em>1999</em> or <em>2003</em></td>
          </tr>

          <tr>
           <td><em>y</em></td>
           <td>A two digit representation of a year</td>
           <td>Examples: <em>99</em> or <em>03</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Time</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>a</em></td>
           <td>Lowercase Ante meridiem and Post meridiem</td>
           <td><em>am</em> or <em>pm</em></td>
          </tr>

          <tr>
           <td><em>A</em></td>
           <td>Uppercase Ante meridiem and Post meridiem</td>
           <td><em>AM</em> or <em>PM</em></td>
          </tr>

          <tr>
           <td><em>B</em></td>
           <td>Swatch Internet time</td>
           <td><em>000</em> through <em>999</em></td>
          </tr>

          <tr>
           <td><em>g</em></td>
           <td>12-hour format of an hour without leading zeros</td>
           <td><em>1</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>G</em></td>
           <td>24-hour format of an hour without leading zeros</td>
           <td><em>0</em> through <em>23</em></td>
          </tr>

          <tr>
           <td><em>h</em></td>
           <td>12-hour format of an hour with leading zeros</td>
           <td><em>01</em> through <em>12</em></td>
          </tr>

          <tr>
           <td><em>H</em></td>
           <td>24-hour format of an hour with leading zeros</td>
           <td><em>00</em> through <em>23</em></td>
          </tr>

          <tr>
           <td><em>i</em></td>
           <td>Minutes with leading zeros</td>
           <td><em>00</em> to <em>59</em></td>
          </tr>

          <tr>
           <td><em>s</em></td>
           <td>Seconds, with leading zeros</td>
           <td><em>00</em> through <em>59</em></td>
          </tr>

          <tr>
           <td><em>u</em></td>
           <td>
            Microseconds (added in PHP 5.2.2). Note that
             <span class="function"><strong>date()</strong></span> will always generate
            <em>000000</em> since it takes an <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>
            parameter, whereas  <span class="methodname"><a href="datetime.format.html" class="methodname">DateTime::format()</a></span> does
            support microseconds.
           </td>
           <td>Example: <em>654321</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Timezone</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>e</em></td>
           <td>Timezone identifier (added in PHP 5.1.0)</td>
           <td>Examples: <em>UTC</em>, <em>GMT</em>, <em>Atlantic/Azores</em></td>
          </tr>

          <tr>
           <td><em>I</em> (capital i)</td>
           <td>Whether or not the date is in daylight saving time</td>
           <td><em>1</em> if Daylight Saving Time, <em>0</em> otherwise.</td>
          </tr>

          <tr>
           <td><em>O</em></td>
           <td>Difference to Greenwich time (GMT) in hours</td>
           <td>Example: <em>+0200</em></td>
          </tr>

          <tr>
           <td><em>P</em></td>
           <td>Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)</td>
           <td>Example: <em>+02:00</em></td>
          </tr>

          <tr>
           <td><em>T</em></td>
           <td>Timezone abbreviation</td>
           <td>Examples: <em>EST</em>, <em>MDT</em> ...</td>
          </tr>

          <tr>
           <td><em>Z</em></td>
           <td>Timezone offset in seconds. The offset for timezones west of UTC is always
           negative, and for those east of UTC is always positive.</td>
           <td><em>-43200</em> through <em>50400</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">Full Date/Time</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>c</em></td>
           <td>ISO 8601 date (added in PHP 5)</td>
           <td>2004-02-12T15:19:21+00:00</td>
          </tr>

          <tr>
           <td><em>r</em></td>
           <td><a href="http://www.faqs.org/rfcs/rfc2822" class="link external">&raquo;&nbsp;RFC 2822</a> formatted date</td>
           <td>Example: <em>Thu, 21 Dec 2000 16:01:07 +0200</em></td>
          </tr>

          <tr>
           <td><em>U</em></td>
           <td>Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)</td>
           <td>See also  <span class="function"><a href="function.time.html" class="function">time()</a></span></td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
       Unrecognized characters in the format string will be printed
       as-is.  The <em>Z</em> format will always return
       <em>0</em> when using  <span class="function"><a href="function.gmdate.html" class="function">gmdate()</a></span>.
      </p>       
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        Since this function only accepts <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> timestamps the
        <em>u</em> format character is only useful when using the
         <span class="function"><a href="function.date-format.html" class="function">date_format()</a></span> function with user based timestamps
        created with  <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span>.
       </p>
      </p></blockquote>
     </dd>

    </dt>

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

   
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a formatted date string. If a non-numeric value is used for 
   <em><code class="parameter">timestamp</code></em>, <strong><code>FALSE</code></strong> is returned and an 
   <strong><code>E_WARNING</code></strong> level error is emitted.
  </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>E_NOTICE</code></strong>
if the time zone is not valid, and/or a <strong><code>E_STRICT</code></strong>
or <strong><code>E_WARNING</code></strong> message
if using the system settings or the <var class="varname"><var class="varname">TZ</var></var> environment
variable. See also  <span class="function"><a href="function.date-default-timezone-set.html" 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>5.1.0</td>
       <td>
        The valid range of a timestamp is typically from Fri, 13 Dec
        1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are
        the dates that correspond to the minimum and maximum values for
        a 32-bit signed integer). However, before PHP 5.1.0 this range was limited
        from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).
       </td>
      </tr>

      
      <tr><td>5.1.0</td><td><p class="para">
Now issues the <strong><code>E_STRICT</code></strong> and <strong><code>E_NOTICE</code></strong>
time zone errors.</p></td></tr>


      <tr>
       <td>5.1.1</td>
       <td>
        There are useful <a href="datetime.constants.html" class="link">constants</a> 
        of standard date/time formats that can be used to specify the 
        <em><code class="parameter">format</code></em> parameter.
       </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-2301">
    <p><strong>Example #1  <span class="function"><strong>date()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;the&nbsp;default&nbsp;timezone&nbsp;to&nbsp;use.&nbsp;Available&nbsp;since&nbsp;PHP&nbsp;5.1<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">//&nbsp;Prints&nbsp;something&nbsp;like:&nbsp;Monday<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Prints&nbsp;something&nbsp;like:&nbsp;Monday&nbsp;8th&nbsp;of&nbsp;August&nbsp;2005&nbsp;03:12:46&nbsp;PM<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l&nbsp;jS&nbsp;\of&nbsp;F&nbsp;Y&nbsp;h:i:s&nbsp;A'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Prints:&nbsp;July&nbsp;1,&nbsp;2000&nbsp;is&nbsp;on&nbsp;a&nbsp;Saturday<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"July&nbsp;1,&nbsp;2000&nbsp;is&nbsp;on&nbsp;a&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;use&nbsp;the&nbsp;constants&nbsp;in&nbsp;the&nbsp;format&nbsp;parameter&nbsp;*/<br />//&nbsp;prints&nbsp;something&nbsp;like:&nbsp;Wed,&nbsp;25&nbsp;Sep&nbsp;2013&nbsp;15:28:57&nbsp;-0700<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_RFC2822</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;prints&nbsp;something&nbsp;like:&nbsp;2000-07-01T00:00:00+00:00<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_ATOM</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</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-2302">
    <p><strong>Example #2 Escaping characters in  <span class="function"><strong>date()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;prints&nbsp;something&nbsp;like:&nbsp;Wednesday&nbsp;the&nbsp;15th<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l&nbsp;\t\h\e&nbsp;jS'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   It is possible to use  <span class="function"><strong>date()</strong></span> and
    <span class="function"><a href="function.mktime.html" class="function">mktime()</a></span> together to find dates in the future
   or the past.
   <div class="example" id="example-2303">
    <p><strong>Example #3  <span class="function"><strong>date()</strong></span> and  <span class="function"><a href="function.mktime.html" class="function">mktime()</a></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$tomorrow&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)&nbsp;&nbsp;,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$lastmonth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)-</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$nextyear&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <p class="para">
     This can be more reliable than simply adding or subtracting the number
     of seconds in a day or month to a timestamp because of daylight saving
     time.
    </p>
   </p></blockquote>
  </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-2304">
    <p><strong>Example #4  <span class="function"><strong>date()</strong></span> Formatting</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Assuming&nbsp;today&nbsp;is&nbsp;March&nbsp;10th,&nbsp;2001,&nbsp;5:16:18&nbsp;pm,&nbsp;and&nbsp;that&nbsp;we&nbsp;are&nbsp;in&nbsp;the<br />//&nbsp;Mountain&nbsp;Standard&nbsp;Time&nbsp;(MST)&nbsp;Time&nbsp;Zone<br /><br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"F&nbsp;j,&nbsp;Y,&nbsp;g:i&nbsp;a"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;March&nbsp;10,&nbsp;2001,&nbsp;5:16&nbsp;pm<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m.d.y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;03.10.01<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"j,&nbsp;n,&nbsp;Y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;10,&nbsp;3,&nbsp;2001<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Ymd"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;20010310<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'h-i-s,&nbsp;j-m-y,&nbsp;it&nbsp;is&nbsp;w&nbsp;Day'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;05-16-18,&nbsp;10-03-01,&nbsp;1631&nbsp;1618&nbsp;6&nbsp;Satpm01<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'\i\t&nbsp;\i\s&nbsp;\t\h\e&nbsp;jS&nbsp;\d\a\y.'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;it&nbsp;is&nbsp;the&nbsp;10th&nbsp;day.<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D&nbsp;M&nbsp;j&nbsp;G:i:s&nbsp;T&nbsp;Y"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Sat&nbsp;Mar&nbsp;10&nbsp;17:16:18&nbsp;MST&nbsp;2001<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'H:m:s&nbsp;\m&nbsp;\i\s\&nbsp;\m\o\n\t\h'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;17:03:18&nbsp;m&nbsp;is&nbsp;month<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"H:i:s"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;17:16:18<br /></span><span style="color: #0000BB">$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y-m-d&nbsp;H:i:s"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;2001-03-10&nbsp;17:16:18&nbsp;(the&nbsp;MySQL&nbsp;DATETIME&nbsp;format)<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   To format dates in other languages, you should use the
    <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span> and  <span class="function"><a href="function.strftime.html" class="function">strftime()</a></span>
   functions 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.html" 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"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER['REQUEST_TIME']</a></var></var> since PHP 5.1.
   </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 class="member"> <span class="function"><a href="function.gmdate.html" class="function" rel="rdfs-seeAlso">gmdate()</a> - Format a GMT/UTC date/time</span></li>
    <li class="member"> <span class="function"><a href="function.idate.html" class="function" rel="rdfs-seeAlso">idate()</a> - Format a local time/date as integer</span></li>
    <li class="member"> <span class="function"><a href="function.getdate.html" class="function" rel="rdfs-seeAlso">getdate()</a> - Get date/time information</span></li>
    <li class="member"> <span class="function"><a href="function.getlastmod.html" class="function" rel="rdfs-seeAlso">getlastmod()</a> - Gets time of last page modification</span></li>
    <li class="member"> <span class="function"><a href="function.mktime.html" class="function" rel="rdfs-seeAlso">mktime()</a> - Get Unix timestamp for a date</span></li>
    <li class="member"> <span class="function"><a href="function.strftime.html" class="function" rel="rdfs-seeAlso">strftime()</a> - Format a local time/date according to locale settings</span></li>
    <li class="member"> <span class="function"><a href="function.time.html" class="function" rel="rdfs-seeAlso">time()</a> - Return current Unix timestamp</span></li>
    <li class="member"> <span class="function"><a href="function.strtotime.html" class="function" rel="rdfs-seeAlso">strtotime()</a> - Parse about any English textual datetime description into a Unix timestamp</span></li>
    <li class="member"><a href="class.datetime.html#datetime.constants.types" class="link">Predefined DateTime Constants</a></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.date-timezone-set.html">date_timezone_set</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.getdate.html">getdate</a></div>
 <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>