我在本地捕捉当月的第一天和最后一天。然后,我想要更进一步,减去12个月,这样我就可以在12个月前和11个月前获得本月的第一天和最后一天。我的问题是,语法永远不会从当前月份改变。以下全部结果产生08/01/2017和08/31/2017获得12个月前在PHP
这应该如何改变,以便它产生准确的结果?
$firstdayofmonth = date('Y-m-01');
$lastdayofmonth = date('Y-m-t');
$firstdayofmonth = date('m-d-Y', strtotime($firstdayofmonth));
$lastdayofmonth = date('m-d-Y', strtotime($lastdayofmonth));
$month12start = date($firstdayofmonth, strtotime("-12 months"));
$month12end = date($lastdayofmonth, strtotime("-12 months"));
$month11start = date($firstdayofmonth, strtotime("-11 months"));
$month11end = date($lastdayofmonth, strtotime("-11 months"));
echo $month12start;
echo $month12end;
echo $month11start;
echo $month11end;
您通过()'的变量,从'日期是一个字符串到一个新的'日期()'调用的格式参数 - 这没有多大意义。 – Qirel
'$ month12start = date('08 -01-2017',strtotime(“ - 12 months”))'没有日期格式的字符,你不会有任何改变。 –
@Qirel - 你会如何推荐我设置它? – BellHopByDayAmetuerCoderByNigh