⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.date-sub.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Subtracts an amount of days, months, years, hours, minutes and seconds from   a DateTime object</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.date-parse.html">date_parse</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.date-sun-info.html">date_sun_info</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-sub" class="refentry"> <div class="refnamediv">  <h1 class="refname">date_sub</h1>  <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">date_sub</span> &mdash; <span class="dc-title">   Subtracts an amount of days, months, years, hours, minutes and seconds from   a DateTime object  </span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><b>date_sub</b></b></span>    ( <span class="methodparam"><span class="type"><span class="type DateTime">DateTime</span></span> <tt class="parameter">$object</tt></span>   , <span class="methodparam"><span class="type"><span class="type DateInterval">DateInterval</span></span> <tt class="parameter">$interval</tt></span>   )</div>  <p class="para rdfs-comment">   Subtracts the specified <b class="classname">DateInterval</b> object from the specified DateTime   object.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term">      <i><tt class="parameter">object</tt></i>     </span>     <dd>      <p class="para">       A date as returned by <b class="classname">DateTime</b>.      </p>     </dd>    </dt>    <dt>     <span class="term">      <i><tt class="parameter">interval</tt></i>     </span>     <dd>      <p class="para">       The amount to be subtracted. For the date use &quot;P3D&quot;, &quot;P3M&quot;, &quot;P3Y&quot; or a       combination of the three e.g. &quot;P2M5D&quot; (Y = Years, M = Months, D = Days.)       MUST BE YEAR MONTH DAY FORMAT &quot;P5Y&quot;, &quot;P5M2D&quot;, &quot;P5Y4D&quot;. For the time use       &quot;T3H&quot;, &quot;T3M&quot;, &quot;T3S&quot; or  or a combination of the three e.g. &quot;T5H20M&quot; (H =       Hours, M = Minutes, S = Seconds). For dateTime us &quot;P5D2M4YT5H20M&quot;. The       digit before the letter (NOT P or T) can be any amount.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   No value is returned.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>date_sub()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$date&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">"18-July-2008&nbsp;16:30:30"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">"d-m-Y&nbsp;H:i:s"</span><span style="color: #007700">).</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">date_sub</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">"P5D"</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">"d-m-Y"</span><span style="color: #007700">).</span><span style="color: #DD0000">'&nbsp;:&nbsp;5&nbsp;Days'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">date_sub</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">"P5M"</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">"d-m-Y"</span><span style="color: #007700">).</span><span style="color: #DD0000">'&nbsp;:&nbsp;5&nbsp;Months'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">date_sub</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">"P5Y"</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">"d-m-Y"</span><span style="color: #007700">).</span><span style="color: #DD0000">'&nbsp;:&nbsp;5&nbsp;Years'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">date_sub</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">"P5Y5M5D"</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">"d-m-Y"</span><span style="color: #007700">).</span><span style="color: #DD0000">'&nbsp;:&nbsp;5&nbsp;Days,&nbsp;5&nbsp;Months,&nbsp;5&nbsp;Years'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">date_sub</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">"P5YT5H"</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">"d-m-Y&nbsp;H:i:s"</span><span style="color: #007700">).</span><span style="color: #DD0000">'&nbsp;:&nbsp;5&nbsp;Years,&nbsp;5&nbsp;Hours'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <div class="warning"><b class="warning">Warning</b><p class="simpara">This function is<em class="emphasis">EXPERIMENTAL</em>. The behaviour of this function, its name, andsurrounding documentation may change without notice in a future release of PHP.This function should be used at your own risk.</p></div> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.date-add.html" class="function" rel="rdfs-seeAlso">date_add()</a></li>    <li class="member"><b>date_diff()</b></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.date-parse.html">date_parse</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.date-sun-info.html">date_sun_info</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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -