java mysql 條件查詢日期時間

2021-06-22 19:28:57 字數 1683 閱讀 9490

1)查詢當天的記錄

select * from hb_article_view where to_days(hb_addtime) = to_days(now())

查詢當前這週的資料

select name,submittime from enterprise where yearweek(date_format(submittime,』%y-%m-%d』)) = yearweek(now());

查詢上週的資料

select name,submittime from enterprise where yearweek(date_format(submittime,』%y-%m-%d』)) = yearweek(now())-1;

查詢當前月份的資料

select name,submittime from enterprise where date_format(submittime,』%y-%m』)=date_format(now(),』%y-%m』)

查詢距離當前現在6個月的資料

select name,submittime from enterprise where submittime between date_sub(now(),interval 6 month) and now();

查詢上個月的資料

select name,submittime from enterprise where date_format(submittime,』%y-%m』)=date_format(date_sub(curdate(), interval 1 month),』%y-%m』)

select * from `user` where date_format(pudate,』%y%m』) = date_format(curdate(),』%y%m』) ;

select * from user where weekofyear(from_unixtime(pudate,』%y-%m-%d』)) = weekofyear(now())

select *

from user

where month(from_unixtime(pudate,』%y-%m-%d』)) = month(now())

select *

from [user]

where year(from_unixtime(pudate,』%y-%m-%d』)) = year(now())

and month(from_unixtime(pudate,』%y-%m-%d』)) = month(now())

select *

from [user]

where pudate between 上月最後一天

and 下月第一天

2)查詢今天的資料:select * from customer where to_days(lastlogintime) =to_days(now());

查詢昨天的資料:select * from customer where to_days(lastlogintime) =to_days(now())-1;

查詢最近7天的資料:select * from customer where to_days(lastlogintime) >to_days(now())-7;

查詢最近30天的資料:select * from customer where to_days(lastlogintime) >to_days(now())-30;

使用Sql按日期條件查詢

查詢當天 1 select from shoporder where datediff day,ordtime,getdate 1 0 查詢當天 2 select from info where datediff dd,datetime,getdate 0 前30天 select from a wh...

SqlServer查詢日期時間範圍條件

查詢當天 select from info where datediff dd,datetime,getdate 0 查詢24小時內的 select from info where datediff hh,datetime,getdate 24 本月記錄 select from 表 where da...

Oracle中日期作為條件的查詢

1.範圍日期的查詢 select from goods where g time between to date 2018 12 26 10 01 59 yyyy mm dd hh24 mi ss and to date 2018 12 26 10 05 17 yyyy mm dd hh24 mi ...