chadmanvb
asked on
compare times with sql
I need to find all the rows in my data base that have a timestamp within the last 30 seconds. One of my columns contains a timestamp in this format 12/13/2011 9:42:27 AM. I need to find all rows that have a time stamp within the last 30 seconds. How can I do this with an sql command?
Select * From tablename where DateDiff(second, datetimecolumne, getdate()) <= 30
ASKER
I'm getting a conversion failed when converting time to char string. Here is the query im using.
Select * From dbo.Workstations where DateDiff(second, CHECKTIME, getdate()) <= 30
The time in i have in my cell is in the following format. 12/13/2011 9:42:27 AM
Select * From dbo.Workstations where DateDiff(second, CHECKTIME, getdate()) <= 30
The time in i have in my cell is in the following format. 12/13/2011 9:42:27 AM
I have you haven't stored the timestamp in a text field, but that is what it looks like.
ASKER
Well I found that a bunch of them did not have a time stamp yet, so I changed the query to just look at one row, but I'm not sure of the syntax. Here is what I have, but it's not right. I just want it to check one row
Select * From dbo.Workstations where DateDiff(second, CHECKTIME, getdate()) <= 30, SERIAL=234454345
Select * From dbo.Workstations where DateDiff(second, CHECKTIME, getdate()) <= 30, SERIAL=234454345
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked great! Thanks