sql得到当前系统时间得
日期部分 CONVERT(varchar(10),getDate(),120)
昨天 select convert(varchar(10),getdate() - 1,120)
明天 select convert(varchar(10),getdate() + 1,120)
最近七天 select * from tb where 时间字段 >= convert(varchar(10),getdate() - 7,120)
随后七天 select * from tb where 时间字段 <= convert(varchar(10),getdate() + 7,120) and 时间字段 >= 时间字段
如果是在表中查詢
--昨天 Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) = 1
--明天 Select * From TableName Where DateDiff(dd, GetDate(), DateTimCol) = 1
--最近七天 Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) <= 7
--随后七天 Select * From TableName Where DateDiff(dd, GetDate(), DateTimCol) <= 7
--上周 Select * From TableName Where DateDiff(wk, DateTimCol, GetDate()) = 1
--本周 Select * From TableName Where DateDiff(wk, DateTimCol, GetDate()) = 0
--下周 Select * From TableName Where DateDiff(wk, GetDate(), DateTimCol ) = 1
--上月 Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 1
--本月 Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 0
--下月 Select * From TableName Where DateDiff(mm, GetDate(), DateTimCol ) = 1
另我写的一个
select top 1 a.topicid,a.title,a.boardid,a.postusername,a.lastpost,a.lastposttime,a.dateandtime,b.boardtype from dv_topic a,dv_board b where a.boardid<>444 and b.boardid=a.boardid AND (a.istop = 1 OR a.isbest = 1) and (DateAndTime BETWEEN (SELECT CONVERT(varchar(10), GETDATE() - 30, 120)) AND (SELECT CONVERT(varchar(10), GETDATE(), 120))) order by Hits desc 一个月内论坛里加为精华或置顶的帖子