--Sql Server中查询今天、本周、本月、一年的数据
表名:applyinfo,字段名:a_lr_date
-- 当天
select * from applyinfo where datediff(day,a_lr_date,getdate())=0;
select * from applyinfo where CAST(a_lr_date AS DATE)=CAST(GETDATE() AS DATE)
-- 最近一周
select DATEADD(WEEK,-1,GETDATE());
select a_lr_date,* from applyinfo where a_lr_date>=DATEADD(WEEK,-1,GETDATE());
select a_lr_date,* from applyinfo where datediff(week,a_lr_date,getdate())=0
SELECT a_lr_date,* FROM applyinfo WHERE datediff(week,a_lr_date,getdate())=0
-- 最近一个月的数据
select dateadd(month,-1,getdate());
select * from applyinfo where a_lr_date>=dateadd(month,-1,getdate());
-- 本年
select YEAR(GETDATE());
select * from applyinfo where YEAR(a_lr_date)=YEAR(GETDATE())