Mutley Posted February 24, 2007 Share Posted February 24, 2007 Hi, Trying to write a script, when someone adds a product to the database it automatically puts the date into a field in the database (DATE 0000-00-00) of the current date. What I want to do is IF the product was submitted within the last 2 weeks to display an image. A "new product" style image. If it's older don't display anything. How would I do this? Link to comment https://forums.phpfreaks.com/topic/39896-if-2-weeks-old/ Share on other sites More sharing options...
skali Posted February 24, 2007 Share Posted February 24, 2007 Use MySQL DATEDIFF(expr1,expr2) function: DATEDIFF() returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Link to comment https://forums.phpfreaks.com/topic/39896-if-2-weeks-old/#findComment-192850 Share on other sites More sharing options...
Barand Posted February 24, 2007 Share Posted February 24, 2007 or $sql = "SELECT prod_id, prod_name, IF(prod_date > CURDATE() - INTERVAL 14 DAY, 'Y', 'N') AS newprod FROM products"; Then output the "new image" when $row['newprod'] == 'Y' Link to comment https://forums.phpfreaks.com/topic/39896-if-2-weeks-old/#findComment-192861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.