Reputation: 2581
I want to read all the user feed entered by the user in the last 2 days. Table - user_feed Column - date_n_time
What i'm looking for - $result = "SELECT content FROM user_feed WHERE date_n_time >= (now() - 2 days)"
Upvotes: 0
Views: 244
Reputation: 838416
There's actually no need to use DATE_SUB
- a simple subtraction works too. The only thing you were missing is the keyword INTERVAL
, and that day
must be singular.
SELECT content
FROM user_feed
WHERE date_n_time >= NOW() - INTERVAL 2 DAY
Upvotes: 1
Reputation: 71170
Use date_sub:
DATE_SUB(CURDATE(), INTERVAL 2 DAY)
So:
$result = "SELECT content FROM user_feed WHERE date_n_time >= DATE_SUB(CURDATE(), INTERVAL 2 DAY) "
Upvotes: 2