php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43997 Date for next month wrong on last day of Month.
Submitted: 2008-01-31 15:36 UTC Modified: 2008-01-31 15:51 UTC
From: gavinp at tbs dot uk dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.4.8 OS: Debian
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: gavinp at tbs dot uk dot com
New email:
PHP Version: OS:

 

 [2008-01-31 15:36 UTC] gavinp at tbs dot uk dot com
Description:
------------
On the last day of the month all of the below bits of code produce two months in advance as oposed to the next month.

So the last day of the month, next month, month +1 etc .. *always* goes two months ahead instead of one.

After having checked the documentation, I don't see or understand how string to time if as next month, would output two months. This cleary is not 'next month'.

Seems to effect all versions of PHP from 4 to at least 5.2.0 (have not tried and tested 5.2.5).

Reproduce code:
---------------
$basedate = time(); 

$date1 = strtotime('next month', $basedate); 
$date2 = strtotime('+1 month', $basedate); 
$date3 = strtotime('first month', $basedate); 
$date4 = mktime(0, 0, 0, date("m")+1, date("d"), date("Y"));

$format1 = date('F', $date1);
$format2 = date('F', $date2);
$format3 = date('F', $date3);
$format4 = date('F', $date4);

echo $format1;
echo $format2;
echo $format3;
echo $format4;

Expected result:
----------------
February
February
February
February

Actual result:
--------------
March
March
March
March

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-31 15:51 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

(And this is expected behavior)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC