Myself Ashutosh Kumar Verma from Varanasi. I am a Software Developer in MindStick Software pvt. ltd. Prayagraj. I have completed my MCA from VBSP. University, Jaunpur in 2021.
To add a time interval in given date in SQL Server, you can use the DATEADD() function. The DATEADD() function takes four arguments:
The first argument is the datepart, which specifies the unit of time that you want to add. For example, you can use day, month, year, hour, minute, or second.
The second argument is the number of units of time that you want to add.
The third argument is the start date.
The fourth argument is the optional fourth argument is the end date.
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
SELECT DATEADD(day, 10, '2023-01-01');
This query will return the value '2023-01-11', which means that the new date is 10 days after the start date.
number is the number of units of time that you want to add.
start_date is the start date.
end_date (optional) is the end date.
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
SELECT DATEADD(hour, 3, '2023-01-01 12:00:00');
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.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
To 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.
DATEADD():
SQL DATEADD() function is used to add a time in given date, like add a year, day or month etc.
Example;