I was trying to do a 'Latest Products' page for an eShop project I'm working on. Basically, I want to show a number of products, say 10, from a table in my db that where added in my database in the last 30 days or less.
First I tried to use the GridView function in VB.NET, where it auto-populates the table but can't be limited and then I tried this SQL statement, which isn't working, giving me an error.
SELECT *
FROM Product
WHERE DateAdded > (SELECT DATEADD(d,-30,(SELCT MAX(DateAdded) FROM Product)) AS "Last 30 Products Added");
ORDER BY DateAdded DESC
My database has a table called 'Product' which has various columns:
Any idea on how I can solve the problem ?
You are looking for the DATEDIFF function to compare the DateAdded with NOW().