set variable to go back one year from today

I Need to insure that I go back one year from today. The variables are both datetime @sdate and @edate, we have the @sdate set to Getdate().  We need to set the @edate  to insure it goes back one year from today..can anyone help.
stevendeveloperAsked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
Something like ...
Declare @sdate datetime, @edate datetime

SELECT @sdate = GETDATE()
SELECT @edate = DATEADD(year, -1, @sdate) 

Open in new window

btw s and e implies Start and End, and in your example start is a year after end.  
Might be confusing.
0
 
stevendeveloperAuthor Commented:
Thanks so Much!
0
 
stevendeveloperAuthor Commented:
SORRY THIS DIDN'T WORK Results below..can you please help.

declare  @sdate         datetime,        
         @edate         datetime
SELECT @sdate = GETDATE()
SELECT @edate = DATEDIFF(year, -1, @sdate)
select @sdate,@edate


RESULTS:
2015-01-30 15:52:01.247
1900-04-27 00:00:00.000
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
stevendeveloperAuthor Commented:
I have it now thanks


declare  @sdate         datetime,        
         @edate         datetime

SELECT @edate = dateadd(yy, -1, GETDATE())
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
My bad, DATEDIFF should have been DATEADD.  Corrected in first post.
0
 
stevendeveloperAuthor Commented:
Thanks...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.