Question

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

Was it helpful?

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

OTHER TIPS

Use:

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

Reference: DATEADD

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top