php.net |  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
 [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 ??

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-31 12:07 UTC] hholzgra@php.net
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] cnewbill@php.net
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.

-Chris

 [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] cnewbill@php.net
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

<?php

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
May
Before: 05
After: 07
October
Before: 10
After: 12

-Chris
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 23:01:26 2024 UTC