Link to home
Start Free TrialLog in
Avatar of sungenwang
sungenwangFlag for United States of America

asked on

SQL query syntax help on time comparison from text string

Experts,

What SQL query syntax should I use to retrieve all records where the processed time is within two minutes? There's a twist: my processed time field is a text field in this format YYYYMMDDHHNNSS (e.g. 20111006114320). I need to select all records where the process time is within two minutes of a specific.

For example, if the current process time is 11:43:20 (20111006114320), then records with these time value should be selected:
11:43:20
11:43:19
11:43:18

This should NOT be selected:
11:43:17
11:43:21

The SQL query syntax needs to work in both MS Access and SQL Server

Thanks in advance!
sew
SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America 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
SOLUTION
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
and you can use

abs(datediff(minute, date1, date2)) <= 2

to find the interval
ASKER CERTIFIED SOLUTION
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
Avatar of sungenwang

ASKER

Thanks to all! Although not exactly what I was looking for but they gave me enough insights to solve my query problem!
sew