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).:(

select * from address
WHERE DateTime
BETWEEN '2009-01-31 09:00:00' AND '2009-01-31 09:34:34'

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.

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.