select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0
select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=1
select * from 表名 where DateDiff(dd,datetime类型字段,getdate())<=7
select * from 表名 where DateDiff(dd,datetime类型字段,getdate())<=30
select * from 表名 where DateDiff(mm,datetime类型字段,getdate())=0
elect * from 表名 where DateDiff(yy,datetime类型字段,getdate())=0
select datepart(dayofyear,getDate())
select datepart(dd, getDate())
select day(getDate())
- 查询本周的星期一日期是多少 (注意:指定日期不能是周日,如果是周日会计算到下周一去。所以如果是周日要减一天)
SELECT DATEADD(wk,DATEDIFF(wk,0,getdate()),0)
select convert(char,dateadd(DD,-1,getdate()),111) //111是样式号,(100-114)
Select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) as firstday
Select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) as firstday
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast((cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' ) as datetime ))))
select datediff(day,'2012/8/1','2012/8/20') as daysum
select convert(char,dateadd(dd,1,'2012/8/20'),111) as riqi //输出2012/8/21
select dateadd(mi,-15,getdate()) //查询当前时间15分钟之前的日期