datetime question

M

Mike Painter

I want to find all events that occurred yesterday.
In Access this would be dateAdd( "d", -1, Date())

How is it expressed in a query in SQL?
Using GetDate() returns an error message.
 
P

Peter Russell

Mike said:
I want to find all events that occurred yesterday.
In Access this would be dateAdd( "d", -1, Date())

How is it expressed in a query in SQL?
Using GetDate() returns an error message.

GetDate() should work.

For an adp:
Select * from Orders where Orderdate = Getdate()-1

Regards

Peter Russell
 
D

dario casubolo

try this:
it is not much elegant but should work fine (at the end of
month / year too)

SELECT *
FROM orders
WHERE (DATEPART(year, orderdate) = DATEPART(year, getdate
() - 1)) AND (DATEPART(month, orderdate) = DATEPART(month,
getdate() - 1)) AND (DATEPART(day, orderdate) = DATEPART
(day, getdate() - 1))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top