您可以使用PHP的strtotime()功能:
// One month from today
$date = date('Y-m-d', strtotime('+1 month'));
// One month from a specific date
$date = date('Y-m-d', strtotime('+1 month', strtotime('2015-01-01')));
只需注意+1 month
並不總是直觀的計算。它似乎總是添加當前月份中存在的天數。
Current Date | +1 month
-----------------------------------------------------
2015-01-01 | 2015-02-01 (+31 days)
2015-01-15 | 2015-02-15 (+31 days)
2015-01-30 | 2015-03-02 (+31 days, skips Feb)
2015-01-31 | 2015-03-03 (+31 days, skips Feb)
2015-02-15 | 2015-03-15 (+28 days)
2015-03-31 | 2015-05-01 (+31 days, skips April)
2015-12-31 | 2016-01-31 (+31 days)
,您可以使用一些其他的日期/時間間隔:
$date = date('Y-m-d'); // Initial date string to use in calculation
$date = date('Y-m-d', strtotime('+1 day', strtotime($date)));
$date = date('Y-m-d', strtotime('+1 week', strtotime($date)));
$date = date('Y-m-d', strtotime('+2 week', strtotime($date)));
$date = date('Y-m-d', strtotime('+1 month', strtotime($date)));
$date = date('Y-m-d', strtotime('+30 days', strtotime($date)));
回答`的strtotime('+ 1個月)',之前看看http://www.gnu.org/software/tar/manual/html_node/Relative-items-in-date-strings .html#SEC120 – Gordon 2010-11-30 22:08:59
如果`end_date`總是`start_date + 1 month`,它不應該在表中。如果沒有,這個評論不適用。 – Danosaure 2010-12-01 02:43:54