php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33013 strtotime - 'next month' doesn't work.
Submitted: 2005-05-12 07:53 UTC Modified: 2005-05-20 13:15 UTC
From: nick at netdupe dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 5.0.4 OS: Mac OS X 10.4
Private report: No CVE-ID: None
 [2005-05-12 07:53 UTC] nick at netdupe dot com
Description:
------------
This bug is fairly self explanatory. But for those who need 
things to be explained, basically if you enter "next month" 
into strtotime you would expect it to give the current time 
+ one month, but it gives the current time + 2 months. Tried 
on several machines same result, seems to have the same 
effect in 5.0.3. I believe there are also problems with 
'next week' etc etc.

'./configure' '--prefix=/usr/local/php5' '--with-config-
file-path=/usr/local/php5/lib' '--with-apxs' '--with-iconv' 
'--with-openssl=/usr' '--with-zlib=/usr' '--with-mysql=/
Users/marc/svn/entropy/php-module/src/mysql-standard-*' '--
with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-
libxml-dir=/usr/local/php5' '--with-xsl=/usr/local/php5' '--
with-pdflib=/usr/local/php5' '--with-pgsql=/Users/marc/svn/
entropy/php-module/build/postgresql-build' '--with-gd' '--
with-jpeg-dir=/usr/local/php5' '--with-png-dir=/usr/local/
php5' '--with-zlib-dir=/usr' '--with-freetype-dir=/usr/
local/php5' '--with-t1lib=/usr/local/php5' '--with-imap=../
imap-2002d' '--with-imap-ssl=/usr' '--with-gettext=/usr/
local/php5' '--with-ming=/Users/marc/svn/entropy/php-module/
build/ming-build' '--with-ldap' '--with-mime-magic=/usr/
local/php5/etc/magic.mime' '--with-iodbc=/usr' '--with-
xmlrpc' '--with-expat-dir=/usr/local/php5' '--with-iconv-
dir=/usr' '--with-curl=/usr/local/php5' '--enable-exif' '--
enable-wddx' '--enable-soap' '--enable-sqlite-utf8' '--
enable-ftp' '--enable-sockets' '--enable-dbx' '--enable-
dbase' '--enable-mbstring' '--enable-calendar' '--with-bz2=/
usr' '--with-mcrypt=/usr/local/php5' '--with-mhash=/usr/
local/php5' '--with-mssql=/usr/local/php5' '--with-fbsql=/
Users/marc/svn/entropy/php-module/build/frontbase-build/
Library/FrontBase' '--enable-openbase_module'

Reproduce code:
---------------
<?php
echo date('F j, Y, g:i a');
echo date('F j, Y, g:i a', strtotime('next month'));

?>

Expected result:
----------------
May 12, 2005, 5:42 pm
June 12, 2005, 5:42 pm

Obviously the dates will be different when you do this.

Actual result:
--------------
May 12, 2005, 5:42 pm
July 12, 2005, 5:42 pm

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-12 22:40 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

first means +1
next means +2
second means +2
... so either use "first month" or "+1 month". No bug here.
 [2005-05-13 01:24 UTC] nick at netdupe dot com
Well I guess this should be a feature change report, because 
anyone with some common sense would conclude that "next month" 
would mean June, not July. Do you go saying "I am going to be 
going on holiday first month"
 [2005-05-13 03:01 UTC] rasmus@php.net
I made this change a while back, but I don't recall the reasoning now.  The GNU page on this clearly states that next=1

http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html

Derick, do you remember what the logic for this was?
 [2005-05-16 13:45 UTC] mgf@php.net
The change was due to bug report http://bugs.php.net/bug.php?id=18655.

It looks like the GNU spec has changed, since at that time we all agreed it said "next" was equivalent to 2 -- I even quoted the relevant section in my contribution to the discussion.  It's more intuitive if "next" is equivalent to 1, so I guess it would be reasonable to change back, just as long as the various changes are sufficiently documented! ;)
 [2005-05-19 21:01 UTC] derick@php.net
I also know the rationale - without "next" linking to 2, there would be no way to represent "2" as "second" already means something else (the time unit). So I think we should not change it back to "1".
 [2005-05-19 21:04 UTC] derick@php.net
Actually, the new parser that I wrote can handle this just fine... so, shall we make next 2 or 1 (in PHP 5.1)?
 [2005-05-20 08:05 UTC] rasmus@php.net
I don't think not having a "second" means that "next" should take its place when it doesn't match the common usage of the word.  The whole point of having these terms at all is to make it easier to use.  If we are going to go to the trouble of making "next month" work, then it should work the way people expect.  Otherwise we should get rid of these terms completely and just go with the more explicit "+1 month" syntax instead.
 [2005-05-20 13:15 UTC] derick@php.net
As we can't remove it because of BC, "next" will now means "1" from now on. "second" will not work in PHP 4.3 (unless I port back my date time stuff) and in PHP 5.0 it won't work at all. PHP 5.1 will support "second second" (+2 seconds) and the like.
 [2010-08-31 16:31 UTC] luket at ukvoipnet dot com
If you are trying to get the month & year of next/previous month try uisng the following function: mktime(0, 0, 0, date("m")+1, 1, date("Y")); using date("m")+1, +2, -1 etc.. as needed. 

You can then place this into a date function as the unix timestamp argument.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC