php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49422 mktime working strange
Submitted: 2009-08-31 08:10 UTC Modified: 2009-08-31 14:21 UTC
From: dolby at xpteam dot eu Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.11RC1 OS: gentoo
Private report: No CVE-ID: None
 [2009-08-31 08:10 UTC] dolby at xpteam dot eu
Description:
------------
I am just wondering is this a bug or expected behaviour:

echo date("r", mktime(0,0,0,9,31,2009));

It returns:
Thu, 01 Oct 2009 00:00:00 +0200

but I "expect" i to be: 
Wed, 30 Sep 2009 00:00:00 +0200

Maybe I am missing the point, but I always supposed the mktime considers real dates.

Reproduce code:
---------------
echo date("r", mktime(0,0,0,9,31,2009));

Expected result:
----------------
Wed, 30 Sep 2009 00:00:00 +0200

Actual result:
--------------
Thu, 01 Oct 2009 00:00:00 +0200

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-31 09:03 UTC] scottmac@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Since there is no September 31st it becomes October 1st, this is expected behavior.
 [2009-08-31 09:56 UTC] dolby at xpteam dot eu
Thank you for your comment. 
I have no intention to use bug zone this a a programming support.

But I have come to this "issue" originally by using:
strtotime("+1month");

And using it on 31.08.2009 will produce the:
Thu, 01 Oct 2009 11:52:57 +0200.

Is this really an expected behaviour ?
If so, I am sorry for misusing this bug system.
 [2009-08-31 14:21 UTC] rasmus@php.net
Yes, that is the way strtotime works.  It uses the standard GNU format just like your Linux command line date program.  You are on Gentoo, so try this today (Aug.31):

date --date='+1 month' +'Next month is %B'

You will find that it says that next month is October.

You can read lots about it here:

http://www.gnu.org/software/tar/manual/html_chapter/Date-input-formats.html

Pay special attention to section "7.6 Relative items in date strings" where it says:

"The fuzz in units can cause problems with relative items. For example, ?2003-07-31 -1 month? might evaluate to 2003-07-01, because 2003-06-31 is an invalid date. To determine the previous month more reliably, you can ask for the month before the 15th of the current month."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 15:01:28 2024 UTC