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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 14:01:34 2025 UTC