php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27789 march returned instead of february with mktime and date
Submitted: 2004-03-30 21:19 UTC Modified: 2010-03-29 23:15 UTC
From: summercom at comcast dot net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.3.5 OS: Windows XP SP1
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: summercom at comcast dot net
New email:
PHP Version: OS:

 

 [2004-03-30 21:19 UTC] summercom at comcast dot net
Description:
------------
When using mktime and the date functions it seems that instead of properly returning "February" the two functions used together will return "March"

Reproduce code:
---------------
<?php
$i = 1;
do {
  
  echo "date(\"F\", mktime(0, 0, 0, $i)); --> ".date("F", mktime(0, 0, 0, $i))."<br />\n";
  $i++;
  
} while ($i < 13);
?>

Expected result:
----------------
date("F", mktime(0, 0, 0, 1)); --> January
date("F", mktime(0, 0, 0, 2)); --> February
date("F", mktime(0, 0, 0, 3)); --> March
date("F", mktime(0, 0, 0, 4)); --> April
date("F", mktime(0, 0, 0, 5)); --> May
date("F", mktime(0, 0, 0, 6)); --> June
date("F", mktime(0, 0, 0, 7)); --> July
date("F", mktime(0, 0, 0, 8)); --> August
date("F", mktime(0, 0, 0, 9)); --> September
date("F", mktime(0, 0, 0, 10)); --> October
date("F", mktime(0, 0, 0, 11)); --> November
date("F", mktime(0, 0, 0, 12)); --> December

Actual result:
--------------
date("F", mktime(0, 0, 0, 1)); --> January
date("F", mktime(0, 0, 0, 2)); --> March
date("F", mktime(0, 0, 0, 3)); --> March
date("F", mktime(0, 0, 0, 4)); --> April
date("F", mktime(0, 0, 0, 5)); --> May
date("F", mktime(0, 0, 0, 6)); --> June
date("F", mktime(0, 0, 0, 7)); --> July
date("F", mktime(0, 0, 0, 8)); --> August
date("F", mktime(0, 0, 0, 9)); --> September
date("F", mktime(0, 0, 0, 10)); --> October
date("F", mktime(0, 0, 0, 11)); --> November
date("F", mktime(0, 0, 0, 12)); --> December

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-30 22:00 UTC] pollita@php.net
Today is the 30th.  When using mktime with only four parameters as you are you'll get the hour, minute, second, and month specified for the current day and year.

February 30th, because it doesn't actually exist, translates out to March 2nd.

Please search the bug database next time.  This has been reported and explained several times already.
 [2010-03-29 18:52 UTC] john at rfnsoftware dot com
$mydate->modify("-1 month") yields same month when current date is March 29-31, since February is 28 or 29 days. So if this was reported in 2004, should not it be corrected yet? Is it programmers responsibility to check - if subracting one month does not change the month then do it again?

I don't call that clutter. I don't have time to search for bug reports all of the time. This one should get fixed ASAP.
 [2010-03-29 23:15 UTC] derick@php.net
john, It's not a bug and it *has* been "fixed": http://derickrethans.nl/obtaining-the-next-month-in-php.html
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 08:01:31 2024 UTC