Add +- 1 Year in SQL Server

add +- 1 year in SQL Server

You are adding the 1 to getdate() so you are adding 1 day

   SELECT ProductName FROM tblProduct WHERE Year BETWEEN 
(year(getdate()) -1) AND (year(getdate()) + 1)

How can I use a SQL UPDATE statement to add 1 year to a DATETIME column?

There is in fact a DATEADD statement in T-SQL, you can find it here

UPDATE Procrastination SET DropDeadDueDate = DATEADD(yyyy,1,DropDeadDueDate)

EDIT: You could use year, yy, or yyyy for the first argument of DATEADD.

Need to find out the date 1 year and 1 year ago from today in SQL

You can also do it like this:

select dateadd(year,-1,dateadd(dd,-1,getdate()))


Related Topics



Leave a reply



Submit