Hi all, trying to display all the products I have added today by using CURDATE but does not seem to be returning any results. I know the issue is in my query. Please see below. Any help would be appreciated.
$query = "SELECT
products.products_id,
products_description.products_name,
products.products_status,
products.products_price,
products.used_condition,
products.actuations
FROM products
INNER JOIN products_description
ON products.products_id = products_description.products_id WHERE products.products_date_added = CURDATE()";
you did not explain how you populate your products_date_added column, so i will guess that it’s either DATETIME or TIMESTAMP, but not DATE
use this –
WHERE products_date_added >= CURRENT_DATE
AND products_date_added < CURRENT_DATE + INTERVAL 1 DAY
this sets up a range test, where the low end of the range is today at midnight this morning, while the upper end of the range is tonight at midnight (actually tomorrow morning at midnight), and the upper end is not included in the range
Bingo! That’s done the trick. Thank you for explainin, it’s good to have an understand of what the problem was rather than just a solutution/fix so thank you once again. Good day to you.