Search code examples
sqlsql-servert-sqlsql-functiongetdate

set date from one year of getdate ()?


I got a DECLARE statement like this

DECLARE ,@ACTIVATE DATETIME,
        @DEACTIVATE DATETIME

I want to set the Activate date as today's date, which is

SET @ACTIVATE = GETDATE()

I want to set the @DEACTIVATE date to one year from the Activate date.

 ACTIVATE = 30/07/2018
 DEACTIVATE = 30/07/2019

I can set DEACTIVATE date using string, but is there any other function or method to do this?

Regards


Solution

  • Use the DATEADD function:

    SET @Deactivate = DATEADD(YEAR, 1, @Activate)