mysql时间段以后_mysql时间段查询
字段column_time的格式為時間格式
from_unixtime將時間戳轉換為時間格式 *做個記號,之前糾結了半天
select * from wap_content where week(column_time) = week(now)
如果你要嚴格要求是某一年的,那可以這樣
查詢一天:
select * from table where to_days(column_time) = to_days(now());
select * from table where date(column_time) = curdate();
查詢一周:
select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time);
查詢一個月:
select * from table where DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(column_time);
========================附
今天
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 7 DAY) <= date(時間字段名)
近30天
Select * FROM 表名 where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(時間字段名)
本月
Select * FROM 表名 Where DATE_FORMAT( 時間字段名, ‘%Y%m’ ) = DATE_FORMAT( CURDATE( ) , ‘%Y%m’ )
上一月
Select * FROM 表名 Where PERIOD_DIFF( date_format( now( ) , ‘%Y%m’ ) , date_format( 時間字段名, ‘%Y%m’ ) ) =1
總結
以上是生活随笔為你收集整理的mysql时间段以后_mysql时间段查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: alxctools索引超出了数组界限_[
- 下一篇: oracle截取字符串替换,oracle