May 27, 2010 at 5:42 am
can some please tell me how to select the previous two years from current year. It is like in the year of 2010 i have to select the 2008, in 2011 i need to select 2009..
thanks much for your help
May 27, 2010 at 5:52 am
you can simply try like this
select year(getdate())- 2
May 27, 2010 at 5:53 am
Hi purushot,, try these:
SELECT
DATEADD(YY, -2 , GETDATE()) AS [2_YRS_BACK_FULLDATE] ,
(DATEPART(YY,GETDATE()) + 2) AS ADD_2YRS
May 27, 2010 at 6:09 am
Thanks
May 27, 2010 at 6:12 am
Without DDL, it's difficult to answer your question. I'd do something like this, if using DATETIME -
DECLARE @currentdate DATETIME,
@lastyear DATETIME,
@twoyearsago DATETIME
SET @currentdate = Getdate()
SET @lastyear=Dateadd(yyyy, -1, @currentdate)
SET @twoyearsago=Dateadd(yyyy, -2, @currentdate)
SELECT @currentdate AS [CurrentDate],
@lastyear AS [1 Year Previous],
@twoyearsago AS [2 Years Previous]
May 27, 2010 at 6:16 am
purushotham.k9 (5/27/2010)
Thanks
You're welcome!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply