Jump to content

Date Time SQL query


aarbrouk

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.