想要创建一个可以在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