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?
chadmanvbAsked:
Who is Participating?
 
CodeCruiserCommented:
Try

Select * From dbo.Workstations where DateDiff(second, CHECKTIME, getdate()) <= 30 AND SERIAL=234454345
0
 
CodeCruiserCommented:
Select * From tablename where DateDiff(second, datetimecolumne, getdate()) <= 30
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
chadmanvbAuthor Commented:
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
0
 
sybeCommented:
I have you haven't stored the timestamp in a text field, but that is what it looks like.
0
 
chadmanvbAuthor Commented:
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
0
 
chadmanvbAuthor Commented:
Worked great!  Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.