Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add one year to a date using SQL script in SQL server?

I am getting a date parameter value as '4-1-2009' from front end. Now I want to make it as

'4-1-2010' in my stored procedure. I am trying like below.

ALTER PROCEDURE [dbo].[SP_EMP]                    

 @STARTDATE DATETIME,

 @ENDDATE DATETIME,

 @STARTDATE2 DATETIME, 

 SET  @STARTDATE2=DATEADD(yy, 1, @STARTDATE)


AS                      
BEGIN 

SELECT EMPNAME FROM EMP WHERE JOINDATE>@STARTDATE2

----//  SOME JOINS //----

END

How can I do this? Please tell me.

Regards, N.SRIRAM

like image 607
sriramjitendra Avatar asked Jan 20 '11 06:01

sriramjitendra


1 Answers

dateAdd function id the solution

SELECT  DATEADD(year, 1, '4-1-2009') FROM  UserLog

Or

Declare @E DATETIME,

SET @E=Select DATEADD(year, 1, '4-1-2009')
like image 89
Jayant Bramhankar Avatar answered Oct 17 '22 09:10

Jayant Bramhankar