SQLServer中DATEDIFF()函数的⽤法DATEDIFF ( datepart , startdate , enddate )
释义:计算时间差;
datepare值:year | quarter | month | week | day | hour | minute | second | millisecond
startdate:开始⽇期
enddate :结束⽇期
GetDate():获取当前的系统⽇期
下⾯例⼦中表名为tablename,条件字段名为inputdate
查询今天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=0
查询昨天
SELECT * FROM tablename where DATEDIFF(day,inputdate,GETDATE())=1
查询本周
SELECT * FROM tablename where DATEDIFF(week,inputdate,GETDATE())=0
查询上周
SELECT * FROM tablename where DATEDIFF(week,inputdate,GETDATE())=1
datediff是字符型函数查询本⽉
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=0
查询上⽉
SELECT * FROM tablename where DATEDIFF(month,inputdate,GETDATE())=1

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。