Search code examples
sqlsql-servert-sqlsql-server-2000date-comparison

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 get on the range value like @id=10.I want to get those values whose are between 9 to 10


Solution

  • 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