From 253e98c2ea0ce43bfd86c6d6d73ad70078eb27b7 Mon Sep 17 00:00:00 2001 From: Christoph Michael Becker Date: Thu, 23 Jun 2016 16:30:38 +0000 Subject: [PATCH] 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 --- reference/datetime/examples.xml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/reference/datetime/examples.xml b/reference/datetime/examples.xml index 0b742687f1..e10ef3946c 100644 --- a/reference/datetime/examples.xml +++ b/reference/datetime/examples.xml @@ -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 +]]> + + + To get the last day of the next month (i.e. to prevent the overflow), + the last day of format is available as of PHP 5.3.0. + + +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; +?> +]]> + + &example.outputs; + +