svn: /phpdoc/en/trunk/reference/datetime/ examples.xml

From: Date: Thu, 23 Jun 2016 16:30:38 +0000
Subject: svn: /phpdoc/en/trunk/reference/datetime/ examples.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-14237@lists.php.net to get a copy of this message
cmb Thu, 23 Jun 2016 16:30:38 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=339460 Log: Fix #72471 Docs to explain how adding/subtracting dates work (PS) Bug: https://bugs.php.net/72471 (Closed) Docs to explain how adding/subtracting dates work Changed paths: U phpdoc/en/trunk/reference/datetime/examples.xml Modified: phpdoc/en/trunk/reference/datetime/examples.xml =================================================================== --- phpdoc/en/trunk/reference/datetime/examples.xml 2016-06-23 16:12:00 UTC (rev 339459) +++ phpdoc/en/trunk/reference/datetime/examples.xml 2016-06-23 16:30:38 UTC (rev 339460) @@ -98,6 +98,38 @@ 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> </para> </section>

« previous php.doc.cvs (#14237) next »