Possible Duplicate:
SQL Select within 24 hours?
I am using regular SQL to attempt to run a query. Here is what my table looks like:
Products
-----------------
Product ID
Date
Weight
The Date is enter as a datetime into the database.
I want to be able to select only the items whos Product.Date is within the past 24 hours. I have been trying to get this for sometime now and here is what I have gotten:
Select Products.Date
FROM Products
WHERE Products.Date < DATEADD(d,-1,CURRENT_TIMESTAMP)
This isn't working for some reason and I get the following product dates:
2011-01-18 00:00:00.000
2010-01-20 14:23:00.000
2011-01-20 04:05:00.000
Could it be that you actually wanted > instead of <?
As per my comment on the other post, if you only want the previous 24 hours (so excluding future dates) then try this:
SELECT Products.Date
FROM Products
WHERE Products.Date BETWEEN DATEADD(d,-1,CURRENT_TIMESTAMP) AND CURRENT_TIMESTAMP
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With