---
title: "How to add a time interval in given date in SQL Server?"  
description: "How to add a time interval in given date in SQL Server?"  
author: "Ashutosh Kumar Verma"  
published: 2021-11-21  
updated: 2024-04-07  
canonical: https://www.mindstick.com/interview/33841/how-to-add-a-time-interval-in-given-date-in-sql-server  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 2 minutes  

---

# How to add a time interval in given date in SQL Server?

## DATEADD():

SQL **DATEADD()** function is used to add a time in given date, like add a year, day or month etc.

Example;

```
SELECT DATEADD(DAY,1,'2020/12/10');
```

```
Output :    2020-12-11 00:00:00.000
```

```
SELECT DATEADD(MONTH,1,'2020/12/10');
```

```
Output:    2021-01-10 00:00:00.000
```

```
SELECT DATEADD(YEAR,1,'2020/12/10');
```

```
Output:     2021-12-10 00:00:00.000
```

## Answers

### Answer by Aryan Kumar

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

```plaintext
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.

Here is the syntax for the DATEADD() function:

SQL

```plaintext
DATEADD ( datepart, number, start_date, end_date )
```

- datepart is the datepart that you want to add.
- 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

```plaintext
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.

### Answer by Ashutosh Kumar Verma

## DATEADD():

SQL **DATEADD()** function is used to add a time in given date, like add a year, day or month etc.

Example;

```
SELECT DATEADD(DAY,1,'2020/12/10');
```

```
Output :    2020-12-11 00:00:00.000
```

```
SELECT DATEADD(MONTH,1,'2020/12/10');
```

```
Output:    2021-01-10 00:00:00.000
```

```
SELECT DATEADD(YEAR,1,'2020/12/10');
```

```
Output:     2021-12-10 00:00:00.000
```


---

Original Source: https://www.mindstick.com/interview/33841/how-to-add-a-time-interval-in-given-date-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
