From: Matthew Stuart [mailto:[EMAIL PROTECTED]

> I have created a sql statement that enables me to select all 
> entries in to MySQL that are dated today, I am trying to do 
> the same for all items that are now one day old and also two 
> days old etc
> 
> I am doing this:
> 
> SELECT *
> FROM table
> WHERE category = 3 AND show = 1 AND date = NOW()-1
> 
> I have it working for todays records, it filters out any that 
> don't match todays date or NOW(), but it still returns the 
> same records for NOW()-1, or NOW()-2. I have tried DATE() but 
> this gives me an error.
> 
> What is the correct syntax for what I am trying to achieve?


You probably want something like this:

SELECT * 
FROM table 
WHERE category = 3 
AND show = 1 
AND date = NOW() - INTERVAL 1 DAY;

Also note that if you're looking specifically at a date, you might want to use 
CURDATE() instead of NOW(), as NOW() returns the full yyyy-mm-dd hh:ii:ss stamp 
(whereas CURDATE() returns just yyyy-mm-dd). MySQL handles it silently just fine, but 
it's a good habit to get into.


-- 
Mike Johnson
Web Developer
Smarter Living, Inc.
phone (617) 886-5539

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to