Fix #72471 Docs to explain how adding/subtracting dates work (PS)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@339460 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christoph Michael Becker 2016-06-23 16:30:38 +00:00
parent 7a94745acb
commit 253e98c2ea

View file

@ -96,6 +96,38 @@ End: 2015-03-03 00:00:00 -05:00
Leap year:
Start: 2016-01-31 00:00:00 -05:00
End: 2016-03-02 00:00:00 -05:00
]]>
</screen>
<simpara>
To get the last day of the next month (i.e. to prevent the overflow),
the <literal>last day of</literal> format is available as of PHP 5.3.0.
</simpara>
<programlisting role="php">
<![CDATA[
<?php
echo "Normal year:\n"; // February has 28 days
$dt = new DateTime("2015-01-31 00:00:00", new DateTimeZone("America/New_York"));
echo "Start: ", $dt->format("Y-m-d H:i:s P"), PHP_EOL;
$dt->modify("last day of next month");
echo "End: ", $dt->format("Y-m-d H:i:s P"), PHP_EOL;
echo "Leap year:\n"; // February has 29 days
$dt = new DateTime("2016-01-31 00:00:00", new DateTimeZone("America/New_York"));
echo "Start: ", $dt->format("Y-m-d H:i:s P"), PHP_EOL;
$dt->modify("last day of next month");
echo "End: ", $dt->format("Y-m-d H:i:s P"), PHP_EOL;
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Normal year:
Start: 2015-01-31 00:00:00 -05:00
End: 2015-02-28 00:00:00 -05:00
Leap year:
Start: 2016-01-31 00:00:00 -05:00
End: 2016-02-29 00:00:00 -05:00
]]>
</screen>
</example>