Link to home
Start Free TrialLog in
Avatar of chadmanvb
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?
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Select * From tablename where DateDiff(second, datetimecolumne, getdate()) <= 30
Avatar of chadmanvb
chadmanvb

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
I have you haven't stored the timestamp in a text field, but that is what it looks like.
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
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked great!  Thanks