Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ID Startdate Enddate
105 2009-04-01 00:00:00.000 2010-03-31 00:00:00.000
108 2010-04-01 00:00:00.000 2011-03-31 00:00:00.000
113 2011-04-01 00:00:00.000 2012-03-31 00:00:00.000
115 2012-04-01 00:00:00.000 2013-03-31 00:00:00.000
120 2013-04-01 00:00:00.000 2014-03-31 00:00:00.000
121 2014-04-01 00:00:00.000 2015-03-31 00:00:00.000
122 2015-04-01 00:00:00.000 2016-03-31 00:00:00.000
i have this data and when i pass today date i sholud get startdate starting from 2015 and startdate staring fom 2016 and 2017 based on current year
means i sholud get three date current previous and future
Posted
Comments
sanjay243657 24-Nov-15 6:36am    
Question not clear Explain clearly.
OriginalGriff 24-Nov-15 6:38am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps an example of exactly what you want output would help?
Use the "Improve question" widget to edit your question and provide better information.
[no name] 24-Nov-15 6:42am    
What have you tried yet ?

To get the year of the current date use
SQL
SELECT YEAR(GetDate())


To select based on the year of the source field

SQL
SELECT * FROM [date_table]
WHERE YEAR(StartDate) = YEAR(GetDate())

To select the next two years as well

SQL
SELECT * FROM [date_table]
WHERE YEAR(StartDate) = YEAR(GetDate())
  OR YEAR(StartDate) = 1 + YEAR(GetDate())
  OR YEAR(StartDate) = 2 + YEAR(GetDate())
 
Share this answer
 
You can get the start date of current year, previous year, next year
SQL
declare @Today datetime
set @Today=getdate()
SELECT DATEADD(yy, DATEDIFF(yy,0,@Today)-1, 0) AS StartOfPreviousYear,
  DATEADD(yy, DATEDIFF(yy,0,@Today), 0) AS StartOfCurrentYear,
   DATEADD(yy, DATEDIFF(yy,0,@Today)+1, 0) AS StartOfNextYear
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900