php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78091 DateTime - subtraction of 1 month return first day of actual month
Submitted: 2019-05-31 11:27 UTC Modified: 2019-05-31 12:38 UTC
From: jan dot zenisek at outlook dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Win 10 / Ubuntu Server
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jan dot zenisek at outlook dot com
New email:
PHP Version: OS:

 

 [2019-05-31 11:27 UTC] jan dot zenisek at outlook dot com
Description:
------------
DateTime->modify

When I subtract 1 month from new DateTime (today is 5th May 2019), I got wrong Date (1st May 2019) but I was expecting April.

Test script:
---------------
var_dump((new \DateTime())->modify('-1 months'));


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-31 12:38 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-05-31 12:38 UTC] requinix@php.net
Assuming you mean today is the 31st,

May 31 - 1 month = April 31, which overflows to May 1.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 21:01:27 2025 UTC