PHP怎麼得出上個月份的,本月的開始時間和結束時間

2021-08-08 20:27:23 字數 875 閱讀 5711

早晨來了,主管讓我寫個指令碼,定時刪除上個月的logs日誌檔案,資料庫中存入了每條記錄的請求時間,我只要找到月份的開始時間和結束時間就行了
<?php

//上當前月份

$month = date("m", strtotime("last month"));

//找到上個月份的開始時間戳和結束時間戳

$days = date("t", strtotime("last month"));

//mktime(hour,minute,second,month,day,year,is_dst);

$lastmonth_year = date("y");

if ($month == 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;

?>

MySQL查詢本週 上週 本月 上個月份的資料

mysql查詢的方式很多,下面為您介紹的mysql查詢實現的是查詢本週 上週 本月 上個月份的資料,如果您對mysql查詢方面感興趣的話,不妨一看。查詢當前這週的資料 selectname,submittimefromenterprisewhereyearweek date format submi...

MySQL查詢本週 上週 本月 上個月份的資料

今天 select from 表名 where to days 時間字段 to days now 昨天 select from 表名 where to days now to days 時間字段 1 近7天 select from 表名 where date sub curdate interval...

MySQL查詢本週 上週 本月 上個月份資料

mysql查詢本週 上週 本月 上個月份資料的sql mysql查詢的方式很多,下面為您介紹的mysql查詢實現的是查詢本週 上週 本月 上個月份的資料,如果您對mysql查詢方面感興趣的話,不妨一看 查詢當前這週的資料 select name,submittime from enterprise ...