因爲數據庫中一般存的都是unix類型的時間,所以要事先轉換一下
查詢固定某一天的語句:
select * from `表名` where from_unixtime(時間字段名,'%Y-%m-%d') =('2017-03-29')
查詢今天,昨天,最近7天,最近30天,本月,上月的語句:
$comsql= "select * from ` 表名` ";
$Today= " where to_days(from_unixtime(時間字段名)) = to_days(now())";
$Ysterday=" where to_days(now()) - to_days(from_unixtime(時間字段名)) = 1";
$Week= " where date_sub(curdate(), INTERVAL 7 DAY) <= date(from_unixtime(時間字段名))";
$Zuijin= " where date_sub(curdate(), INTERVAL 30 DAY) <= date(from_unixtime(時間字段名))";
$Month= " where date_format(from_unixtime(時間字段名), '%Y%m') = date_format(curdate() , '%Y%m')";
$LastMonth=" where period_diff(date_format(now() , '%Y%m') , date_format(from_unixtime(時間字段名), '%Y%m')) =1";