开发者

how to compare server time

work on Sql server 2000. i want to get the current server date and time then want to compare it with my table column EntryDate .How to?

Declare @id datetime

Select @id = DATEPART(hour,GETDATE())

SELECT [Name],[BirthDate],[Email]
FROM Customers3 where BirthDate<=@id-1 AND BirthDate>=@id

want to 开发者_如何学Pythonget on the range value like @id=10.I want to get those values whose are between 9 to 10


Use:

WHERE t.birthdate BETWEEN DATEADD(hh, -1, GETDATE()) AND GETDATE()

Reference: DATEADD


You need to use the query along the DatePart() like this:

Declare @id datetime

Select @id = DATEPART(hour,GETDATE())

SELECT [Name],[BirthDate],[Email]
FROM Customers3 
where DatePart(HOUR,BirthDate) between @id-1 AND @id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜