Guys, I am trying to write a stored procedure in T-SQL (SQL Server) that will select records based on a date field, keeping a variance of minutes in mind. Something like this:
CREATE PROCEDURE spGetCustomers(@DateRange DATETIME, @Variance int) AS
-- The next line is where I need help
-- I'm trying to subtract X amount of minutes from the date
-- So if @Variance = 4 AND @DateRange = '6/10/2009 1:15pm'
-- Then @StartDate should equal '6/10/2009 1:11pm'
DECLARE @StartDate = @DateRange - @Variance
-- I also need an @EndDate, which will be X amount of minutes
-- in the future. So if @Variance = 4 AND @DateRange = '6/10/2009 1:15pm'
-- Then @EndDate should equal '6/10/2009 1:19pm'
DECLARE @EndDate = @DateRange + @Variance
SELECT * FROM Customers WHERE Created BETWEEN @StartDate AND @EndDate
Hopefully this makes sense and someone can help me out! Thanks in advance