aarbrouk Posted March 16, 2009 Share Posted March 16, 2009 Hello, I am trying to display the latest products that have been added in stock... I have a "DateAdded" field in my products table... Could someone tell me how I query the table to pull out the products that have been added a month between the "DateAdded" and the Current Date?? Help would be much appreciated Link to comment https://forums.phpfreaks.com/topic/149690-date-time-sql-query/ Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 DATE_SUB(curdate(), INTERVAL 3 MONTH); Link to comment https://forums.phpfreaks.com/topic/149690-date-time-sql-query/#findComment-786043 Share on other sites More sharing options...
aarbrouk Posted March 16, 2009 Author Share Posted March 16, 2009 What is the DATE_SUB?? so far I have: "SELECT * FROM product WHERE product.ProductStatus='Active' AND product.DateAdded =DATE_SUB(curdate(), INTERVAL 1 MONTH) ORDER BY RAND() LIMIT 4"; This error comes up: SELECT * FROM product WHERE product.ProductStatus='Active' AND product.DateAddedDATE_SUB(curdate(), INTERVAL 3 MONTH) ORDER BY RAND() LIMIT 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY RAND() LIMIT 4' at line 1 Link to comment https://forums.phpfreaks.com/topic/149690-date-time-sql-query/#findComment-786057 Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 Try; $sql = "SELECT * FROM product p WHERE p.ProductStatus='Active' AND DATE_SUB(curdate(), INTERVAL 3 MONTH) Link to comment https://forums.phpfreaks.com/topic/149690-date-time-sql-query/#findComment-786061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.