How to query for today's date and 7 days before data?

前端 未结 2 1949
借酒劲吻你
借酒劲吻你 2021-02-19 01:37

I\'m using sql server 2008. How to query out a data which is the date is today and 7 days before today ?

相关标签:
2条回答
  • 2021-02-19 02:22

    Try this way:

    select * from tab
    where DateCol between DateAdd(DD,-7,GETDATE() ) and GETDATE() 
    
    0 讨论(0)
  • 2021-02-19 02:33

    Query in Parado's answer is correct, if you want to use MySql too instead GETDATE() you must use (because you've tagged this question with Sql server and Mysql):

    select * from tab
    where DateCol between affffdate(now(),-7) and now() 
    
    0 讨论(0)
提交回复
热议问题