取当前日期前6个月的最后一天


Get the last day of the next 6 months prior to the current date

我的代码有问题,得到未来6个月的最后一天。我的代码首先得到当前月的最后一天,然后使用日期函数+ 6个月。

$lastday = date("Y-m-t");
$lastdayaftersixmonth = strtotime("$lastday +6 months");

但我的问题是,当涉及到月份没有相同的天数,特别是在八月和二月的情况下。如果八月的最后一天是31,它应该返回2月28日(或闰年29日),但它返回3月2日。

$日期=日期(Y-m-t, strtotime(' + 6个月'));echo $日期;