0

I need some help creating a query that will pull a series of record that falls with a date range with specific interval.

for example: I would like pass in a date like getdate() - 10 for start date and getdate() for the end date. However, the dates in between (which is the timestamp of the record) the two dates should be between (x second, minutes or hours apart).:(

3
Contributors
3
Replies
9
Views
8 Years
Discussion Span
Last Post by darkagn
0
select * from address
WHERE DateTime
BETWEEN '2009-01-31 09:00:00' AND '2009-01-31 09:34:34'
0

What I like to get done is a bit more complex than that; but thank you for the partial solution. what you have will only give me all the dates that are between the start and the end date.

What I really need help with is to be able to look for dates that are between the start and the stop date in addition to return all the occurrences that are within +/- say 15sec. of the broad interval's start time.

0

The DATEADD function will do what you need. Its syntax is DATEADD(datepart,number,date) where the datepart parameter is the interval that you are adding (eg second which can be abbreviated to ss), the number parameter is the amount you are adding (eg 15 or -15) and the date parameter is the date that you are adding to (eg '2009-03-17 12:15:45'). So your query, using freshfitz's example, would be:

SELECT * FROM address
WHERE DateTime
BETWEEN DATEADD(ss,-15,'2009-01-31 09:00:00') AND DATEADD(ss,15,'2009-01-31 09:34:34')

HTH,
d :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.