Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help obtaining a date in a query

Status
Not open for further replies.

limester

Technical User
Dec 29, 2004
69
CA
Hi,

I have a date column and I am trying to build a query that will give me the dates > 48 hours ago (in the past).

For example using todays date 2006.10.05 and time 23:00 I would be looking for the dates prior to 2006.10.03 and time 23:00.

Your help is greatly appreciated!

Thanks!
 
Have a look on datediff function..you can use this function with your date column and getdate function ..

Regards,


"There are no secrets to success. It is the result of preparation, hard work, and learning from failure." -- Colin Powell
 
... give me the dates > 48 hours ago

For example using todays date 2006.10.05 and time 23:00 I would be looking for the dates prior to 2006.10.03 and time 23:00.
I am not sure what you want but you easyly can change the query.

Code:
DECLARE @dtCurrentDate datetime

SET @dtCurrentDate = DATEADD(hh,-48,GETDATE())
-- or SET @dtCurrentDate = DATEADD(dd,-2,GETDATE())
-- two days are 48 h, right?

SELECT *
       FROM MyTable
       WHERE DateTimeField >= @dtCurrentDate

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
This works great!

Thanks for the replies!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top