Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting records from 'n' days ago against datetime field 1

Status
Not open for further replies.

mbabcock

Programmer
Jul 25, 2006
32
US
I've got a table with a datetime field, and I want to create a Stored Proc that retrieves records 'n' days back using an input parameter. Kind of like this:

input parameter: @tiPastDays INT

declare @dPastDate
@dPastDate = CURRENT_DATE - @tiPastDays

select * from MyTable where tTheDateFieldToAnalyze >= @dPastDate

Mind you I'm dealing with dates only and don't care about the time portion.

tia!
--Michael
 
one way

declare @tiPastDays int
select @tiPastDays =5

declare @dPastDate datetime
select @dPastDate = convert(varchar(10),dateadd(d, -@tiPastDays,getdate()),112)
--select @dPastDate

select * from MyTable where tTheDateFieldToAnalyze >= @dPastDate

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top