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

Asked

Viewed 1,627 times

3

After viewing the that question, the following doubt arose that is, in the case that the date field is in the following format 2014-12-11 11:06:09, how to return only the last 7 days?

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 believe there’s an easier way to do it.

-2

Do so:

SELECT * FROM sua_tabela WHERE seu_campo
BETWEEN date(date(now()) - 7) and date(now());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.