ID:               43999
 User updated by:  gavinp at tbs dot uk dot com
 Reported By:      gavinp at tbs dot uk dot com
 Status:           Open
 Bug Type:         Date/time related
 Operating System: Debian
 PHP Version:      4.4.8
 New Comment:

Excatly. Hence why it's a bug.

I'm asking PHP to add 1 to the month number. Not to add 31 days to the
month.

strtotime('next month', $basedate); where $basedate = today

The expected result would be to produce the next month, not to add 31
days and provide the month, which may, or may not be, the next month.


Previous Comments:
------------------------------------------------------------------------

[2008-01-31 16:37:20] scott at slerman dot net

Today is January 31st.
Adding 1 to the month would produce February 31st.
February 31st does not exist, so it is converted to March 2nd (or March
3rd during non-leap years).

The GNU date format documentation
(http://www.gnu.org/software/tar/manual/html_node/tar_113.html) gives
you the solution of getting the next month after the 15th of the current
month. You can do this in PHP with the second parameter to strtotime:

strtotime('next month', mktime(0, 0, 0, idate('m'), 15))

------------------------------------------------------------------------

[2008-01-31 16:20:48] gavinp at tbs dot uk dot com

Description:
------------
Hi [EMAIL PROTECTED],

I have not posted this twice,(however because you locked the last bug I
now have to and in case another user has ... your search system will
need some work then. I could not find a bug describing the same problem.
Please direct me to the correct place that is an open bug and I will
happy tag this onto the end of it.

strtotime('next month', $basedate); where $basedate = today.

Should output the next month. The next month from today is Feb. Simple.
That is the 'expected behaviour'.

That's like saying 2+2 = 4 except on Fridays when it = 5, and then
saying because it's always been like this then it's 'Expected.'

If you are going to refer me to the documentation, please direct me to
the documentations excact location where it says 'next month on the last
day of the month should be two months instead of one.' I can not find
this part in the documentation anywhere also.

However I would love to eat humble pie so please do show me.

Reproduce code:
---------------
$basedate = time(); 

$date1 = strtotime('next month', $basedate); 
$date2 = strtotime('+1 month', $basedate); 
$date3 = strtotime('first month', $basedate); 
$date4 = mktime(0, 0, 0, date("m")+1, date("d"), date("Y"));

$format1 = date('F', $date1);
$format2 = date('F', $date2);
$format3 = date('F', $date3);
$format4 = date('F', $date4);

echo $format1;
echo $format2;
echo $format3;
echo $format4;


Expected result:
----------------
February
February
February
February

Actual result:
--------------
March
March
March
March


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=43999&edit=1

Reply via email to