这样,比如:
表名为:tableName
时间字段名为:theDate

查询本月的记录
select * from tableName where DATEPART(mm, theDate) = DATEPART(mm, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())

查询本周的记录
select * from tableName where DATEPART(wk, theDate) = DATEPART(wk, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())

查询本季的记录
select * from tableName where DATEPART(qq, theDate) = DATEPART(qq, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())

其中:GETDATE()是获得系统时间的函数。

获取一周的星期几

 DATENAME(weekday, getdate())

设置一周的第一天: SET DATEFIRST 1

 

posted on 2009-06-22 16:06  Burt  阅读(216)  评论(0编辑  收藏  举报