想要創建一個可以在PHP中執行此操作的函數。PHP:在不超過月份的最後一天的情況下添加月份
我需要在月份的最後一天添加月份數,但不能超過 。
例如:
Add 1 month to January (1-28th), 2011, should produce February (1-28th), 2011.
Add 1 month to January 30th, 2011, should produce February 28th, 2011.
Add 3 months to January 31st, 2011, should produce April 30th, 2011.
Add 13 months to January 30th, 2011, should produce February 29th, 2012.
Add 1 month to October 31st, 2011, should produce November 30th, 2011.
如果我使用日期此外在PHP中,我得到超支:
Adding 1 month to January 30th, 2011, results in March 2nd, 2011.
我的規範不允許我溢出到一個新的月份。
最簡單的方法是什麼?
我加了一些例子。 – 2011-04-22 22:59:11