PHP将日期添加到月末

时间:2012-11-27 15:42:35

标签: php

  

可能重复:
  PHP last day of the month

我必须为我的申请设定一个到期日。

首位用户必须选择上市时间,例如1年,今天是2012年11月25日

然后我们必须将此1年添加到当前日期,并自动将到期日期设置为月末。即到期日将 2013年11月30日

如果当前日期是2012年10月4日并且选择1年的持续时间,则到期日为2012年10月31日。

我成功地在当前日期添加了一两年/几年,但是如何找出它的月末?

3 个答案:

答案 0 :(得分:3)

你可以这样做:

echo date("Y-m-t", strtotime("+1 year"));

See the DOCs for strtotime

using t for the date function to get the last day of the month

答案 1 :(得分:2)

以下内容适用于您:

echo date("Y-m-t", strtotime("+1 year"));

答案 2 :(得分:-1)

试试这段代码:

echo date(date('t',strtotime($date)) . '-M-Y', strtotime($date . ' +1 year'));
相关问题