// 本月第一天
$firstDate = date("Y-m-01", strtotime($date));
// 上月的第一天和最后一天
$syFirstDay = date('Y-m-01',strtotime('-1 day', strtotime($firstDate)));
$syLastDay = date('Y-m-d',strtotime('-1 day', strtotime($firstDate)));
本文介绍了一种使用PHP进行日期操作的方法,包括获取当前月份的第一天、上个月的第一天和最后一天。通过简单的strtotime函数和date函数组合,可以轻松实现日期的转换。
// 本月第一天
$firstDate = date("Y-m-01", strtotime($date));
// 上月的第一天和最后一天
$syFirstDay = date('Y-m-01',strtotime('-1 day', strtotime($firstDate)));
$syLastDay = date('Y-m-d',strtotime('-1 day', strtotime($firstDate)));
1万+
1032

被折叠的 条评论
为什么被折叠?