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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

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: Fri May 10 04:01:31 2024 UTC