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)
 select records which were added in last 24 hours

Author  Topic 

kam
Starting Member

17 Posts

Posted - 2006-03-28 : 17:30:41
I have a dateTime column which stores the date and time the record is added to the table. What I wish to do is use a query and select all the records which were added in the last 24 hours.

I attempted this with the following statement, but to no luck:

SELECT jobID
FROM jobRequest
WHERE DATEDIFF(hour, dateReported, getdate() ) <= 24


Can someone provide any suggestions?

Thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-28 : 17:32:30
try this
SELECT jobID
FROM jobRequest
WHERE dateReported >= DATEADD(day, -1, getdate())





KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

kam
Starting Member

17 Posts

Posted - 2006-03-29 : 12:43:28
it works! thanks.
Go to Top of Page
   

- Advertisement -