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)
 Query for time period smaller than one day

Author  Topic 

nemohm
Yak Posting Veteran

69 Posts

Posted - 2003-04-28 : 14:26:31
I 'm wondering what is the way to specify periods of time smaller then a day( 1 hour, 1min)
in WHERE clause in a query?

Thx,

Dobby

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2003-04-28 : 14:31:00
Sure,

In BOL,

DATEDIFF ( datepart , startdate , enddate )

Datepart Abbreviations
Year yy, yyyy
quarter qq, q
Month mm, m
dayofyear dy, y
Day dd, d
Week wk, ww
Hour hh
minute mi, n
second ss, s
millisecond ms

Jeremy

Go to Top of Page

nemohm
Yak Posting Veteran

69 Posts

Posted - 2003-04-28 : 15:07:17

Actually my goal is to get every row that appeared in the last 1 hour; or last minute:

Select *
From table
Where logstamp IN …. – one hour period in the past from this moment

Dobby
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-04-28 : 15:13:50
For last hour:

Select *
From table1
Where logstamp > DATEADD(hour, -1, getdate())

For last minute:

Select *
From table1
Where logstamp > DATEADD(minute, -1, getdate())

Tara
Go to Top of Page

nemohm
Yak Posting Veteran

69 Posts

Posted - 2003-04-28 : 15:41:49
Tara,

Thanks a lot !

Dobby
Go to Top of Page
   

- Advertisement -