Or you can use a function like YEAR(), which returns the result as an integer: SELECT YEAR(DATEADD(year, 10, '')) AS 'Future Year' +-+-+-+-+īut it’s important to note that the FORMAT() function returns its result as a string.Īnother option is to use CONVERT() to convert the result to a date data type: SELECT CONVERT(date, DATEADD(year, 10, '')) AS Converted We can take the above result and format it with the FORMAT() function: SELECTįORMAT(DATEADD(year, 10, ''), 'yyyy-MM-dd') AS 'yyyy-MM-dd',įORMAT(DATEADD(year, 10, ''), 'dd/MM/yyyy') AS 'dd/MM/yyyy',įORMAT(DATEADD(year, 10, ''), 'yyyy') AS 'yyyy',įORMAT(DATEADD(year, 10, ''), 'yy') AS 'yy' For example, if you provide a datetime2 argument, the return value will be datetime2. In cases where you don’t supply a string literal, the return value is the same as the data type of the date argument. When you supply a string literal as the date, DATEADD() returns a datetime value. The reason it’s returned as this data type is because we supplied a string literal as the date argument. This is because the result is returned as a datetime value.
![dateadd sql server dateadd sql server](https://i.ytimg.com/vi/_hwybLkIISQ/maxresdefault.jpg)
In this case, the return value includes the time component as well as the date. Here’s a basic example of adding ten years to a date: SELECT DATEADD(year, 10, '') AS 'Future Date' Where datepart is the part of the date you want to be increased (or decreased), number is the amount to increase datepart by, and date is the date to which the addition will take place. The syntax of DATEADD() goes like this: DATEADD (datepart, number, date ) This article contains examples to demonstrate. For example, you could take ‘’, add 10 years, then return the (increased) year component. You can also combine DATEADD() with other functions to format the date as required.
![dateadd sql server dateadd sql server](https://codepedia.info/mediaUpload/article/Last-date-Previous-month-sql-server_637454400509410839.jpg)
You can also use it to subtract a specified time period. In SQL Server, you can use the DATEADD() function to add a specified time period to a given date.