Sophie

Sophie

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

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>Get Unix timestamp for a date</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.microtime.html">microtime</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strftime.html">strftime</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.mktime" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mktime</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mktime</span> &mdash; <span class="dc-title">Get Unix timestamp for a date</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mktime-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>mktime</strong></span>
    ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$hour</code><span class="initializer"> = date(&quot;H&quot;)</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$minute</code><span class="initializer"> = date(&quot;i&quot;)</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$second</code><span class="initializer"> = date(&quot;s&quot;)</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$month</code><span class="initializer"> = date(&quot;n&quot;)</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$day</code><span class="initializer"> = date(&quot;j&quot;)</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$year</code><span class="initializer"> = date(&quot;Y&quot;)</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$is_dst</code><span class="initializer"> = -1</span></span>
  ]]]]]]] )</div>

  <p class="para rdfs-comment">
   Returns the Unix timestamp corresponding to the arguments
   given. This timestamp is a long integer containing the number of
   seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time
   specified.
  </p>
  <p class="para">
   Arguments may be left out in order from right to left; any
   arguments thus omitted will be set to the current value according
   to the local date and time.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mktime-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    As of PHP 5.1, when called with no arguments,  <span class="function"><strong>mktime()</strong></span>
    throws an <strong><code>E_STRICT</code></strong> notice: use the 
     <span class="function"><a href="function.time.html" class="function">time()</a></span> function instead.
   </p>
  </p></blockquote>
 </div>


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

    <dt>

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

      <p class="para">
       The number of the hour relative to the start of the day determined by
       <em><code class="parameter">month</code></em>, <em><code class="parameter">day</code></em> and <em><code class="parameter">year</code></em>.
       Negative values reference the hour before midnight of the day in question.
       Values greater than 23 reference the appropriate hour in the following day(s).
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The number of the minute relative to the start of the <em><code class="parameter">hour</code></em>.
       Negative values reference the minute in the previous hour.
       Values greater than 59 reference the appropriate minute in the following hour(s).
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The number of seconds relative to the start of the <em><code class="parameter">minute</code></em>.
       Negative values reference the second in the previous minute.
       Values greater than 59 reference the appropriate second in the following minute(s).
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The number of the month relative to the end of the previous year.
       Values 1 to 12 reference the normal calendar months of the year in question.
       Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc.
       Values greater than 12 reference the appropriate month in the following year(s).
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The number of the day relative to the end of the previous month.
       Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month.
       Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc.
       Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The number of the year, may be a two or four digit value,
       with values between 0-69 mapping to 2000-2069 and 70-100 to
       1970-2000. On systems where time_t is a 32bit signed integer, as
       most common today, the valid range for <em><code class="parameter">year</code></em> 
       is somewhere between 1901 and 2038. However, before PHP 5.1.0 this
       range was limited from 1970 to 2038 on some systems (e.g. Windows).
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       This parameter can be set to 1 if the time is during daylight savings time (DST), 
       0 if it is not, or -1 (the default) if it is unknown whether the time is within 
       daylight savings time or not. If it&#039;s unknown, PHP tries to figure it out itself.
       This can cause unexpected (but not incorrect) results.
       Some times are invalid if DST is enabled on the system PHP is running on or 
       <em><code class="parameter">is_dst</code></em> is set to 1. If DST is enabled in e.g. 2:00, all times 
       between 2:00 and 3:00 are invalid and  <span class="function"><strong>mktime()</strong></span> returns an undefined 
       (usually negative) value. 
       Some systems (e.g. Solaris 8) enable DST at midnight so time 0:30 of the day when DST 
       is enabled is evaluated as 23:30 of the previous day.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        As of PHP 5.1.0, this parameter became deprecated. As a result, the
        new timezone handling features should be used instead.
       </p>
      </p></blockquote>
     </dd>

    </dt>

   </dl>

  </p>
 </div>
                                                                                                            
   
  
 <div class="refsect1 returnvalues" id="refsect1-function.mktime-returnvalues">
  <h3 class="title">Return Values</h3> 
  <p class="para">
    <span class="function"><strong>mktime()</strong></span> returns the Unix timestamp of the arguments
   given.
   If the arguments are invalid, the function returns <strong><code>FALSE</code></strong> (before PHP 5.1
   it returned <em>-1</em>).
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.mktime-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.mktime-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.3.0</td>
       <td>
         <span class="function"><strong>mktime()</strong></span> now throws <strong><code>E_DEPRECATED</code></strong> notice 
        if the <em><code class="parameter">is_dst</code></em> parameter is used.
       </td>
      </tr>

      <tr>
       <td>5.1.0</td>
       <td>
        The <em><code class="parameter">is_dst</code></em> parameter became deprecated.
        Made the function return <strong><code>FALSE</code></strong> on error, instead of
        <em>-1</em>.
        Fixed the function to accept the year, month and day to be all passed
        as zero.
       </td>
      </tr>

      <tr>
       <td>5.1.0</td>
       <td>
        When called with no arguments,  <span class="function"><strong>mktime()</strong></span> throws 
        <strong><code>E_STRICT</code></strong> notice. Use the 
         <span class="function"><a href="function.time.html" class="function">time()</a></span> function instead.
       </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>


     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mktime-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2315">
    <p><strong>Example #1  <span class="function"><strong>mktime()</strong></span> basic example</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;as&nbsp;of&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 /></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;Prints&nbsp;something&nbsp;like:&nbsp;2006-04-05T01:02:03+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: #DD0000">'c'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2006</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2316">
    <p><strong>Example #2  <span class="function"><strong>mktime()</strong></span> example</strong></p>
    <div class="example-contents"><p>
      <span class="function"><strong>mktime()</strong></span> is useful for doing date arithmetic
     and validation, as it will automatically calculate the correct
     value for out-of-range input. For example, each of the following
     lines produces the string &quot;Jan-01-1998&quot;.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&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;</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">12</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">32</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1997</span><span style="color: #007700">));<br />echo&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;</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">13</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1997</span><span style="color: #007700">));<br />echo&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;</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">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1998</span><span style="color: #007700">));<br />echo&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;</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">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">98</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2317">
    <p><strong>Example #3 Last day of a month</strong></p>
    <div class="example-contents"><p>
     The last day of any given month can be expressed as the &quot;0&quot; day
     of the next month, not the -1 day. Both of the following examples
     will produce the string &quot;The last day in Feb 2000 is: 29&quot;.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$lastday&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">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"Last&nbsp;day&nbsp;in&nbsp;Feb&nbsp;2000&nbsp;is:&nbsp;%d"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$lastday</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$lastday&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">4</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">31</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2000</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"Last&nbsp;day&nbsp;in&nbsp;Feb&nbsp;2000&nbsp;is:&nbsp;%d"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$lastday</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.mktime-notes">
  <h3 class="title">Notes</h3>
  <div class="caution"><strong class="caution">Caution</strong>
   <p class="para">
    Before PHP 5.1.0, negative timestamps were not supported under any known
    version of Windows and some other systems as well. Therefore the range of
    valid years was limited to 1970 through 2038.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mktime-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.checkdate.html" class="function" rel="rdfs-seeAlso">checkdate()</a> - Validate a Gregorian date</span></li>
    <li class="member"> <span class="function"><a href="function.gmmktime.html" class="function" rel="rdfs-seeAlso">gmmktime()</a> - Get Unix timestamp for a GMT date</span></li>
    <li class="member"> <span class="function"><a href="function.date.html" class="function" rel="rdfs-seeAlso">date()</a> - Format a local time/date</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>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.microtime.html">microtime</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strftime.html">strftime</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>