mysql 時間查詢

2021-08-25 19:38:05 字數 2417 閱讀 5547

select * from member where datediff(now(),mem_reg_time) = 0;   // 查詢今天註冊的會員

select * from member where datediff(now(),mem_reg_time) = 1; // 查詢昨天註冊的會員

select * from member where datediff(now(),mem_reg_time) < n;   // 查詢最近n天註冊的會員

今天select * from signn where to_days(signdate) = to_days(now());

昨天select * from signn where to_days(now()) - to_days(signdate) = 1;

昨天和今天

select * from signn where to_days(now()) - to_days(signdate) <= 1;

7天select * from 表名 where date_sub(curdate(), interval 7 day) <= date(時間欄位名)

select * from signn where date_sub(curdate(), interval 7 day) <= date(signdate);

近30天

select * from 表名 where date_sub(curdate(), interval 30 day) <= date(時間欄位名)

select * from signn where date_sub(curdate(), interval 30 day) <= date(signdate);

本月select * from 表名 where date_format(時間欄位名, '%y%m' ) = date_format( curdate( ) , '%y%m' )

select * from signn where date_format(signdate, '%y%m') = date_format(curdate(), '%y%m')

上一月select * from 表名 where period_diff( date_format( now( ) , '%y%m' ) , date_format( 時間欄位名, '%y%m' ) ) =1

select * from signn where period_diff(date_format(now(), '%y%m'), date_format(signdate, '%y%m')) = 1

查詢一周:

select * from table   where date_sub(curdate(), interval 7 day) <= date(column_time);

select * from signn where date_sub(curdate(), interval 7 day) <= date(signdate);

查詢乙個月:

select * from table where date_sub(curdate(), interval 1 month) <= date(column_time);

select * from signn where date_sub(curdate(), interval 1 month) <= date(signdate);

查詢本季度資料

select * from `ht_invoice_information` where quarter(create_date)=quarter(now());

select * from signn where quarter(signdate) = quarter(now());

查詢上季度資料

select * from `ht_invoice_information` where quarter(create_date)=quarter(date_sub(now(),interval 1 quarter));

select * from signn where quarter(signdate) = quarter(date_sub(now(),interval 1 quarter));

查詢本年資料

select * from `ht_invoice_information` where year(create_date)=year(now());

select * from signn where year(signdate) = year(now());

查詢上年資料

select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));

select * from signn where year(signdate) = year(date_sub(now(), interval 1 year));

mysql時間查詢 MySQL按時間查詢

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 int...

mysql 時間查詢

mysql查詢今天 昨天 7天 近30天 本月 上一月 資料 推薦scofield php開發 seo sem 查詢今天 select from 表名 where to days 時間欄位名 to days now 昨天select from 表名 where to days now to days...

Mysql時間查詢

但是前端傳入的引數確是 yyyy mm dd 的 沒有帶時分秒。如果按照下面這兩種方式會查不全 select from test where create time between 2018 07 30 and 2018 07 31 select from test where create tim...