我想获取上一个日历月的开始日期和结束日期。日期操作问题
因此,现在是2012年7月,我希望函数将2012年6月1日作为开始时间和2012年6月30日作为结束时间返回。
这是我的代码:
$current_month = date("Y-m-01 00:00:00");
$start_month = strtotime(date("Y-m-d", strtotime($current_month) . " -1 month"));
$end_month = strtotime(date("Y-m-d", strtotime($current_month) . " -1 second"));
echo "Start Month: " . date('Y-m-d',$start_month) . "(" . $start_month . ")<br>";
echo "End Month: " . date('Y-m-d',$end_month) . "(" . $end_month . ")<br>";
但回声的:
Start Month: 2012-07-01(1341093600)
End Month: 2012-07-01(1341093600)
任何想法,我做错了吗?
检查这一点,它可以帮助你http://stackoverflow.com/questions/9735604/the-best-way-to-get-the-上个月的第一个和最后一个月 – Adi 2012-07-10 06:46:52