Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATE_SUB()

Status
Not open for further replies.

dude333

Programmer
Feb 5, 2004
11
GB
Hi,

I am trying to select all the records in a database table from a given date to 30 days before.

I have this:


"SELECT * FROM records WHERE DATE_SUB('2004-03-15', interval 30 day) AND id=1 ORDER BY date ASC";


For some reason this ignores the date claculation and returns all records in the table for that id.

Can anyone tell me where I am going wrong?

Thanks.
 
Just in case anyone has a similar problem a solution appears to be:


SELECT * FROM records WHERE id=1 AND (date > DATE_SUB('2004-03-15', INTERVAL 29 DAY)
AND date < DATE_SUB('2004-03-15', INTERVAL 0 DAY)) ORDER BY date ASC;

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top