Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to compare two times that are stored in DateTime datatype?? part2 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
What I really need is something like this:

SELECT something FROM sometable
WHERE EXEC CompareTime(sometable.time, GETDATE() )

It doesn't work to call the comparetime-procedure just like that (I've tested) but somehow would need to be able to call a CompareTime-stored procedure from within another stored procedure.

This is a a try from me to better explain what I want to do when comparing 2 times (note, 2 times, no date should be compared, only the time).
I want to be able to do it in SQL Server 7 like it's possible to do in Access97 where one can use TIME() to get the time at the moment.
Bob Nachbar
 

SELECT *
FROM SomeTable
WHERE DATEPART(hour,date) = 5
AND DATEPART(minute,date) = 30

would return anything matching 5:30 am...

SELECT *
FROM SomeTable
WHERE DATEPART(hour,date) = DATEPART(hour,getdate())
AND DATEPART(minute,date) = DATEPART(minute,getdate())

would return anything matching the current time.

Hope this helps...

 
Thanks for your help Darkman!

My stored procedure is now working correctly, with some modifications to your syntax (still using DATEPART etc).

//Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top