摘要:可用来获取表中今天、昨天、本周、上周、本月、上月等数据
函数:DATEDIFF ( datepart , startdate , enddate )
- datepare值:year | quarter | month | week | day | hour | minute | second | millisecond
- startdate:开始日期
- enddate :结束日期
功能:计算时间差
函数:GetDate()
功能:获取当前的系统时间
表名为tbname,
条件字段名为datename(时间类型的字段)
查询今天
SELECT * FROM tbname where DATEDIFF(day,datename,GETDATE())=0
查询昨天
SELECT * FROM tbname where DATEDIFF(day,datename,GETDATE())=1
查询本周
SELECT * FROM tbname where datediff(week,datename,getdate())=0
查询上周
SELECT * FROM tbname where datediff(week,datename,getdate())=1
查询本月
SELECT * FROM tbname where DATEDIFF(month,datename,GETDATE())=0
查询上月
SELECT * FROM tbname where DATEDIFF(month,datename,GETDATE())=1
查询本季度的
select * from T_InterViewInfo where datediff(QQ,datename,getdate())=0