Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 1287

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>Creates a new DateInterval object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.dateinterval.html">DateInterval</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="dateinterval.createfromdatestring.html">DateInterval::createFromDateString</a></div>
 <div class="up"><a href="class.dateinterval.html">DateInterval</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="dateinterval.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateInterval::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0)</p><p class="refpurpose"><span class="refname">DateInterval::__construct</span> &mdash; <span class="dc-title">Creates a new DateInterval object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-dateinterval.construct-description">
  <h3 class="title">Description</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span>  <span class="methodname"><strong>DateInterval::__construct()</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$interval_spec</code></span>
   )</div>

  <p class="para rdfs-comment">
   Creates a new DateInterval object.
  </p>
 </div>


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

    <dt>

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

      <p class="para">
       An interval specification.
      </p>
      <p class="para">
       The format starts with the letter <em>P</em>,
       for "<span class="quote">period.</span>"
       Each duration period is represented by an integer value
       followed by a period designator.
       If the duration contains time elements, that portion
       of the specification is preceded by the letter
       <em>T</em>.
      </p>
      <p class="para">
       <table class="doctable table">
        <caption><strong>
         <em><code class="parameter">interval_spec</code></em> Period Designators
        </strong></caption>
        
         <thead>
          <tr>
           <th>Period Designator</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><em>Y</em></td>
           <td>years</td>
          </tr>

          <tr>
           <td><em>M</em></td>
           <td>months</td>
          </tr>

          <tr>
           <td><em>D</em></td>
           <td>days</td>
          </tr>

          <tr>
           <td><em>W</em></td>
           <td>
            weeks. These get converted into days,
            so can not be combined with <em>D</em>.
           </td>
          </tr>

          <tr>
           <td><em>H</em></td>
           <td>hours</td>
          </tr>

          <tr>
           <td><em>M</em></td>
           <td>minutes</td>
          </tr>

          <tr>
           <td><em>S</em></td>
           <td>seconds</td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
       Here are some simple examples.
       Two days is <em>P2D</em>.
       Two seconds is <em>PT2S</em>.
       Six years and five minutes is <em>P6YT5M</em>.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        The unit types must be entered from the largest
        scale unit on the left to the smallest scale unit
        on the right.
        So years before months, months before days,
        days before minutes, etc.
        Thus one year and four days must be represented as
        <em>P1Y4D</em>, not <em>P4D1Y</em>.
       </p>
      </p></blockquote>
      <p class="para">
       The specification can also be represented as a date time.
       A sample of one year and four days would be
       <em>P0001-00-04T00:00:00</em>.
       But the values in this format can not exceed a given period&#039;s
       roll-over-point (e.g. <em>25</em> hours is invalid).
      </p>
      <p class="para">
       These formats are based on the <a href="http://en.wikipedia.org/wiki/Iso8601#Durations" class="link external">&raquo;&nbsp;ISO 8601 duration
       specification</a>.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-dateinterval.construct-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Throws an <a href="class.exception.html" class="classname">Exception</a> when the <em><code class="parameter">interval_spec</code></em>
   cannot be parsed as an interval.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-dateinterval.construct-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2285">
    <p><strong>Example #1 <a href="class.dateinterval.html" class="classname">DateInterval</a> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$interval&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">'P2Y4DT6H8M'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$interval</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
object(DateInterval)#1 (8) {
  [&quot;y&quot;]=&gt;
  int(2)
  [&quot;m&quot;]=&gt;
  int(0)
  [&quot;d&quot;]=&gt;
  int(4)
  [&quot;h&quot;]=&gt;
  int(6)
  [&quot;i&quot;]=&gt;
  int(8)
  [&quot;s&quot;]=&gt;
  int(0)
  [&quot;invert&quot;]=&gt;
  int(0)
  [&quot;days&quot;]=&gt;
  bool(false)
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-dateinterval.construct-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="dateinterval.format.html" class="function" rel="rdfs-seeAlso">DateInterval::format()</a> - Formats the interval</span></li>
    <li class="member"> <span class="function"><a href="datetime.add.html" class="function" rel="rdfs-seeAlso">DateTime::add()</a> - Adds an amount of days, months, years, hours, minutes and seconds to a
   DateTime object</span></li>
    <li class="member"> <span class="function"><a href="datetime.sub.html" class="function" rel="rdfs-seeAlso">DateTime::sub()</a> - Subtracts an amount of days, months, years, hours, minutes and seconds from
   a DateTime object</span></li>
    <li class="member"> <span class="function"><a href="datetime.diff.html" class="function" rel="rdfs-seeAlso">DateTime::diff()</a> - Returns the difference between two DateTime objects</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="class.dateinterval.html">DateInterval</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="dateinterval.createfromdatestring.html">DateInterval::createFromDateString</a></div>
 <div class="up"><a href="class.dateinterval.html">DateInterval</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>