AJ OP
AJ OP

Reputation: 445

How to SELECT data from table only recorded the last three days

I recorded data in field 'date' by mysql NOW() function. I want to SELECT data which recorded the last three days(today, yesterday and the day before yesterday),but no idea to do this.

SELECT * FROM tlb_students WHERE date ...?... ORDER BY date DESC LIMIT 20

Upvotes: 3

Views: 4786

Answers (4)

DrinkJavaCodeJava
DrinkJavaCodeJava

Reputation: 808

Another way to do it is:

SELECT * FROM tlb_students WHERE date < DATE_ADD(CURDATE(),INTERVAL -3 DAY)

Upvotes: 1

tsukimi
tsukimi

Reputation: 1645

WHERE date >= subdate(NOW(), 2) 

Upvotes: 2

Zane Bien
Zane Bien

Reputation: 23125

SELECT * 
FROM tlb_students 
WHERE date >= NOW() - INTERVAL 3 DAY
ORDER BY date DESC
LIMIT 20

Upvotes: 4

sel
sel

Reputation: 4957

WHERE date >= ( CURDATE() - INTERVAL 3 DAY )

Upvotes: 4

Related Questions