php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34898 strtotime
Submitted: 2005-10-17 22:21 UTC Modified: 2005-10-31 16:33 UTC
From: alancox+php at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.0.5 OS: Debian Sarge
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: alancox+php at gmail dot com
New email:
PHP Version: OS:

 

 [2005-10-17 22:21 UTC] alancox+php at gmail dot com
Description:
------------
The strtotime function doesn't always add one month when you ask it to.

Reproduce code:
---------------
$date = "2005-10-31 23:59:59";
echo date( "Y-m-t H:i:s", strtotime( "+1 month", strtotime($date) ) );   // 2005-12-31 23:59:59

$date = "2005-10-30 23:59:59";
echo date( "Y-m-t H:i:s", strtotime( "+1 month", strtotime($date) ) );   // 2005-11-30 23:59:59

Expected result:
----------------
Both echos should be 2005-11-30 23:59:59.  The first one is incorrect.

Actual result:
--------------
2005-12-31 23:59:592005-11-30 23:59:59

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-17 22:24 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-10-17 22:40 UTC] derick@php.net
No bug here.

1. you used the "t" modifier where you should have used "d"
2. There is no november 31st, so that get's rounded up to december 1st


 [2005-10-31 16:33 UTC] alancox+php at gmail dot com
Today is Oct. 31st.  If I do 

date("Y-m-d H:i:s", strtotime("+1 month"));

I get this ...

2005-12-01 10:28:42

There is no reason that strtotime should decide to round November 31st to December 1st.  It is October.  If I add one month to October, I get November.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 20:01:29 2024 UTC