Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 find people who have created an account 2hours ago

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2004-07-28 : 23:27:50

I have a table which has person_ID and account_create_date

Person_id account_create_date
----------------------------------

1001 2004-07-28 09:15:15.160
1002 2004-07-28 14:15:15.160
1003 2004-07-28 15:15:15.160
1004 2004-07-28 20:04:15.160
1005 2004-07-28 20:15:15.160
.
.
.

I would like to find out a list of people who have created an account 2hours ago( from getdate).
For example, if the current time is 10:00 pm ,
the output should looks like:

1004 2004-07-28 20:04:15.160
1005 2004-07-28 20:15:15.160
[/code]

something like
where account_create_date > datepart(hh,getdate) - 2




timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-07-28 : 23:36:31
You're close...

SELECT PersonID, CreateDate
FROM table
WHERE DateDiff(hh, CreateDate, GetDate()) <= 2

Go to Top of Page

Pat Phelan
Posting Yak Master

187 Posts

Posted - 2004-07-28 : 23:37:03
How about:
where account_create_date > DateAdd(hour, -2, GetDate())
-PatP
Go to Top of Page
   

- Advertisement -