Reputation: 1141
I have a select query that retrieves all entries that are 3 weeks old.
I want to know if there is an expression like where date> Expr (CURDATE () - 3 WEEKS)
or if I must first make calculations of differences in my php script.
The format of my date is a timestamp
like that : 2010-06-21 16:59:59
Sincerely,
Upvotes: 3
Views: 6539
Reputation: 191
you can use the following line of code
where date>DATE_SUB(curdate(),INTERVAL 3 WEEK);
Upvotes: 7
Reputation: 47331
Use the actual input of timestamp is better,
as it allow query cache to take effect
Queries that contain non-deterministic functions aren’t cached. That includes CURDATE(), RAND(), or any other function where the output isn’t always the same.
From documentation :- http://dev.mysql.com/doc/refman/5.1/en/query-cache-operation.html
Upvotes: 2
Reputation: 38345
You can use the DATEDIFF()
function like so: WHERE DATEDIFF(CURDATE(), date) = 21
.
Upvotes: 5