|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13888 Date + October
Submitted: 2001-10-31 11:57 UTC Modified: 2001-10-31 12:46 UTC
From: pmartinez at distridasa dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.0.4pl1 OS: Red Hat 6.2
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: pmartinez at distridasa dot com
New email:
PHP Version: OS:


 [2001-10-31 11:57 UTC] pmartinez at distridasa dot com
I have a problem with date() function;

In my PC, Today is 31-October-2001.
I would like to obtain precedent month and next month with this clause:

$month_before = date('m',  mktime(0,0,0,date("m")-1,date("d"),date("Y")));

$month_next = date('m',  mktime(0,0,0,date("m")+1,date("d"),date("Y")));

Surprisingly, I get this result:
$month_before is equal to 10
$month_next is equal to 12

This error just ocurrs this day "31-10-2001". Another day is ok.

I don't understand it !!!

Can anyone help me ??


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-31 12:07 UTC]
might be daylight saving time related?

it's always better to use mktime(12,0,0,...
instead of mktime(0,0,0,... 
when you care about date only but not time ...
 [2001-10-31 12:11 UTC]
There is no Novemeber 31st, this is why it is returning December; it skips to the equivalent day which would be the 1st of Dec. Same with Septemeber.

This is desired behavior.


 [2001-10-31 12:26 UTC] pmartinez at distridasa dot com
I'm disagree with cnewbill.

For example in 30 Apr, next was 01 May, and in 30 Jun next was 01 Jul.

Why in october doesn't it work?
 [2001-10-31 12:46 UTC]
Again same result and same reason.  What does April 30th and June 30th have to do with your problem??

Last I checked the calendar works like this

So you're telling me that 9/31 isn't the same calendar day as October 1st and Novemember 31st isn't the same calendar day as Dec 1st??

Sept   Oct          Nov          Dec
30     1 2 3 ... 31 1 2 3 ... 30 1 2 3


print "May\n";
print "Before: ".date("m", mktime(0,0,0,(5-1),31,2001))."\n";
print "After: ".date("m", mktime(0,0,0,(5+1),31,2001)). "\n";

print "October\n";
print "Before: ".date("m", mktime(0,0,0,(10-1),31,2001))."\n";
print "After: ".date("m", mktime(0,0,0,(10+1),31,2001)). "\n";


[cnewbill@storm cnewbill]$ php -q t.php
Before: 05
After: 07
Before: 10
After: 12

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 01:01:31 2024 UTC