php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79453 Modify -1 month works incorrectly at the end of some months
Submitted: 2020-04-07 06:03 UTC Modified: 2020-04-07 08:55 UTC
From: moras dot pawel at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.2.29 OS: Ubuntu 19.04
Private report: No CVE-ID: None
 [2020-04-07 06:03 UTC] moras dot pawel at gmail dot com
Description:
------------
`modify` result is not intuitive when going back one month. If the current month has more days than the last one, modify ('-1 month') can end up in the same month. I believe, if that is the case, it should fall back to the last day of last month.

The current way this works is completely unintuitive, and at least should be mentioned in the docs. 


Test script:
---------------
$date = new DateTime ();
$date->setDate (2020, 03, 30); // 31 days in march
echo $date->format ("Y-m-d h:m:s") . PHP_EOL;

$date->modify ("-1 month"); // only 28 days in february
echo $date->format ("Y-m-d h:m:s") . PHP_EOL;


Expected result:
----------------
2020-03-30 07:03:18
2020-02-28 07:03:18


Actual result:
--------------
2020-03-30 07:03:18
2020-03-01 07:03:18


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-07 06:08 UTC] requinix@php.net
-Type: Bug +Type: Documentation Problem
 [2020-04-07 08:55 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2020-04-07 08:55 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is already documented at https://www.php.net/manual/en/datetime.examples-arithmetic.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 03:01:29 2024 UTC