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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 - 28 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 14:01:34 2024 UTC