How to add a time interval in given date in SQL Server?
1162
21-Nov-2021
Updated on 07-Apr-2024
Aryan Kumar
20-Jun-2023To add a time interval in given date in SQL Server, you can use the DATEADD() function. The DATEADD() function takes four arguments:
The DATEADD() function returns the new date that is created by adding the specified time interval to the start date. For example, the following query will add 10 days to the date '2023-01-01':
SQL
This query will return the value '2023-01-11', which means that the new date is 10 days after the start date.
Here is the syntax for the DATEADD() function:
SQL
The DATEADD() function can also be used to add a time interval to a datetime. For example, the following query will add 3 hours to the datetime '2023-01-01 12:00:00':
SQL
This query will return the value '2023-01-01 15:00:00', which means that the new datetime is 3 hours after the start datetime.
Ashutosh Kumar Verma
21-Nov-2021DATEADD():
SQL DATEADD() function is used to add a time in given date, like add a year, day or month etc.
Example;