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 一个月内论坛里加为精华或置顶的帖子

相关文章:

  • 2021-11-03
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2021-07-02
  • 2021-11-28
  • 2021-12-12
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
相关资源
相似解决方案