Search the data of the last 7 days from the current date (2014-12-11 11:06:09)

3

After viewing the this question , the following question arose, which is, in case the date field is in the next format 2014-12-11 11:06:09, how can I return only the last 7 days?

    
asked by anonymous 05.02.2015 / 19:41

2 answers

4

I tested it here and it worked:

SELECT * FROM sua_tabela WHERE seu_campo
BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 day)) AND NOW();
  

I think you have an easier way to do it.

    
05.02.2015 / 19:50
-2

Do this:

SELECT * FROM sua_tabela WHERE seu_campo
BETWEEN date(date(now()) - 7) and date(now());
    
23.10.2018 / 16:43