1.今天
select * from hb_contract_in h where to_days(modify_date)=to_days(now());
2.昨天
select * from hb_contract_in h where to_days(now())-to_days(modify_date)<=1;
3.近七天
select * from hb_contract_in where date_sub(curdate(), interval 7 day) <= date(modify_date);
4.近30天
select * from hb_contract_in where date_sub(curdate(), interval 30 day) <= date(modify_date);
5.本月
select * from hb_contract_in where date_format( modify_date, '%y%m' ) = date_format( curdate( ) , '%y%m' );
6.上一月
select * from hb_contract_in where period_diff( date_format( now( ) , '%y%m' ) , date_format( modify_date, '%y%m' ) ) =1;
7.查詢本季度資料
select * from hb_contract_in where quarter(modify_date)=quarter(now());
8.查詢上季度資料
select * from hb_contract_in where quarter(modify_date)=quarter(date_sub(now(),interval 1 quarter));
9.查詢本年資料
select * from hb_contract_in where year(modify_date)=year(now());
10.查詢上年資料
select * from hb_contract_in where year(modify_date)=year(date_sub(now(),interval 1 year));
11.查詢當前這週的資料
select * from hb_contract_in where yearweek(date_format(modify_date,'%y-%m-%d')) = yearweek(now());
12.查詢上週的資料
select * from hb_contract_in where yearweek(date_format(modify_date,'%y-%m-%d')) = yearweek(now())-1;
13.查詢當前月份的資料
select * from hb_contract_in where date_format(modify_date,'%y-%m')=date_format(now(),'%y-%m');
14.查詢距離當前現在6個月的資料
select * from hb_contract_in where modify_date between date_sub(now(),interval 6 month) and now();
mysql指定日期加
mysql時間加減函式為date add date sub 定義和用法 date add 函式向日期新增指定的時間間隔。date sub 函式向日期減少指定的時間間隔。語法date add date,interval expr type date sub date,interval expr typ...
sqlServer 獲取每月固定日期
比如獲取固定26日 1.獲取年 select convert varchar 5 year getdate 2.獲取月 select convert varchar 5 month getdate 3.26 數字寫死 不轉時間格式 字串 convert varchar 5 year getdate ...
mysql 查詢指定日期格式
mysql 查詢指定日期格式,使用 date format date,format 函式 select date format create date,y m d h i s as create date from tableselect date format a.submit time,y as...