1. 事情是这样婶儿的
早晨来了,主管让我写个脚本,定时删除上个月的logs日志文件,数据库中存入了每条记录的请求时间,我只要找到月份的开始时间和结束时间就行了
2. 代码
<?php
$month = date("m", strtotime("last month"));
$days = date("t", strtotime("last month"));
$lastmonth_year = date("Y");
if ($month == 1) {
$year = date("Y");
$lastmonth_year = $year - 1;
}
$begin = mktime(0, 0, 0, $month, 1, $lastmonth_year);
$end = mktime(23, 59, 59, $month, $days, $lastmonth_year);
$month = date("Y-m");
$month_begin_date = $month . "-01";
$month_begin = strtotime($month_begin_date);
$next = strtotime("next month");
$next_month_begin_date = date("Y-m",$next) . "-01";
$month_end = strtotime($next_month_begin_date) - 1;
?>