I tried some date functions, because I would like to get some dates of the next month with PHP, but I experienced some problems.
The current date as a MySQL-compatible timestamp (date('Y-m-d H:i:s');) is the following:
'2012-05-31 14:59:19'
date('t', strtotime('next month'));which gives the number of days in the next month, returns 31 as a result… which is not correct, because June consists of only 30 days (seems like it outputs the days of July).date('Y-m-d H:i:s', strtotime('next month'));, which gives the next month’s timestamp format, returns'2012-07-01 14:59:19', but I would expect the following:
'2012-06-30 14:59:19'.
So I tried some codes, here are my experiments, using date(), strtotime() and DateTime class: http://pastebin.com/3iaH4iSZ
And the OUTPUT looks like the following (you can also see it here!):

Are these PHP bugs, or do I misunderstand something?
I would expect the same results as when using MySQL’s date functions, just a few examples:
SELECT NOW( )
2012-05-31 17:51:15
SELECT DATE_ADD(NOW(), INTERVAL 1 MONTH)
2012-06-30 17:51:15
SELECT DATE_ADD( '2013-01-30 17:51:15', INTERVAL 1 MONTH )
2013-02-28 17:51:15
SELECT DATE_ADD( '2013-01-31 17:51:15', INTERVAL 1 MONTH )
2013-02-28 17:51:15
OK, I think I found the solution, which behaves similar to MySQL’s
DATE_ADDfunction withINTERNAL 1 MONTH.I tested my function with all the possibly problematic cases, and it seems to work correctly.
I paste it here, maybe someone will find it useful. I put some comments in this code, so I think it’s clear enough.
The function is called
getOneMonthLaterTimestamp. An example:Output: 2012-06-30 17:51:15
The function
Test cases
Output of the test cases
I pasted the output here: http://pastebin.com/rY5ZRBs9.
Here’s a screenshot of it: https://i.stack.imgur.com/9q23l.png
Getting the number of days in the next month
Test case
Output: