[SQLServer]
表名为: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())

 

查询3个月以内的数据

select * from tableName where datepart(dd,getdate() - theDate)<90


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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-02-08
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案