當天
select * from `order` where to_days(輸入時間欄位名) = to_days((輸入時間欄位名);
昨天select * from `order` where to_days( now( ) ) - to_days(輸入時間欄位名) <= 1
7天select * from `order` where date_sub(curdate(), interval 7 day) <= date(輸入時間欄位名)
近30天
select * from `order` where date_sub(curdate(), interval 30 day) <= date(輸入時間欄位名)
本月select * from `order` where date_format( 輸入時間欄位名, '%y%m' ) = date_format( curdate( ) , '%y%m' )
上一月select * from `order` where period_diff( date_format( now( ) , '%y%m' ) , date_format( 輸入時間欄位名, '%y%m' ) ) =1
#查詢本季度資料
select * from `ht_invoice_information` where quarter(create_date)=quarter(now());
#查詢上季度資料
select * from `ht_invoice_information` where quarter(create_date)=quarter(date_sub(now(),interval 1 quarter));
#查詢本年資料
select * from `ht_invoice_information` where year(create_date)=year(now());
#查詢上年資料
select * from `ht_invoice_information` where year(create_date)=year(date_sub(now(),interval 1 year));
查詢當前這週的資料
select name,submittime from `order` where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now());
查詢上週的資料
select name,submittime from `order` where yearweek(date_format(submittime,'%y-%m-%d')) = yearweek(now())-1;
查詢當前月份的資料
select name,submittime from `order` where date_format(submittime,'%y-%m')=date_format(now(),'%y-%m')
查詢距離當前現在6個月的資料
select name,submittime from `order` where submittime between date_sub(now(),interval 6 month) and now();
查詢上個月的資料
select name,submittime from `order` where date_format(submittime,'%y-%m')=date_format(date_sub(curdate(), interval 1 month),'%y-%m')
select * from `order` where date_format(pudate, ' %y%m ' ) = date_format(curdate(), ' %y%m ' ) ;
select * from `order` where weekofyear(from_unixtime(pudate,'%y-%m-%d')) = weekofyear(now())
select *
from `order`
where month (from_unixtime(pudate, ' %y-%m-%d ' )) = month (now())
select *
from [ `order` ]
where year (from_unixtime(pudate, ' %y-%m-%d ' )) = year (now())
and month (from_unixtime(pudate, ' %y-%m-%d ' )) = month (now())
select *
from [ `order` ]
where pudate between 上月最後一天
and 下月第一天
where date(regdate) = curdate();
select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())
select date( c_instime ) ,curdate( )
from `t_score`
where 1
limit 0 , 30
mysql 查詢時間轉換 Mysql 查詢時間轉換
利用data format函式 select date format now y m d 根據format字串格式化date值 s,s 兩位數字形式的秒 00,01,59 i,i 兩位數字形式的分 00,01,59 h 兩位數字形式的小時,24 小時 00,01,23 h 兩位數字形式的小時,12 ...
MySQL查詢時間函式
今天是 select now 2015 09 28 13 48 12 查詢當天,格式為yyyy mm dd select curdate 2015 09 28 查詢當天,格式為yyyy mm dd hh mm ss select now 2015 09 28 13 42 00 查詢當天0點,格式為y...
mysql查詢時間範圍
前端傳入的引數確是 yyyy mm dd 的 沒有帶時分秒。如果按照下面這兩種方式會查不全 select from test where create time between 2018 07 30 and 2018 07 31 select from test where create time ...