例如:

  今天的所有数据:select * from 表名 where DateDiff(dd,开始时间,getdate())=0

  昨天的所有数据:select * from 表名 where DateDiff(dd,开始时间,getdate())=1

  7天内的所有数据:select * from 表名 where DateDiff(dd,开始时间,getdate())<=7

  30天内的所有数据:select * from 表名 where DateDiff(dd,开始时间,getdate())<=30

  本月的所有数据:select * from 表名 where DateDiff(mm,开始时间,getdate())=0

  本年的所有数据:select * from 表名 where DateDiff(yy,开始时间,getdate())=0

 

DATEDIFF 函数

DATEDIFF(datepart,startdate,enddate)

startdate 和 enddate 参数是合法的日期表达式。

datepart 参数可以是下列的值:

SQL 查询过去时间内的数据

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2022-02-18
  • 2022-12-23
  • 2021-12-03
  • 2021-12-03
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-12-18
  • 2021-12-03
  • 2022-12-23
  • 2022-01-04
相关资源
相似解决方案