# DATE\_DELTA

**The function DATE\_DELTA returns returns the number of total years, total months, and total days between two DATES.**

This function takes two [Dates](../../variable-data-types/the-date-variable-data-type) as input. It returns he number of total years, total months, and total days between the two Dates. This output is technically formatted as another [Date](../../variable-data-types/the-date-variable-data-type), but, unlike most [Dates](../../variable-data-types/the-date-variable-data-type), it does not express a valid date. Calculation takes into account irregularities such as daylight savings time and leap years.

#### Declaration

```javascript
DATE_DELTA(date1, date2) -> delta
```

&#x20;

#### Parameters

**date1** (required, type: _Date_) Any date.

**date2** (required, type: _Date_) Any date.

#### Return Values

**delta** (type: _Date_) The number of total years, total months, and total days between two **date1** and **date2**. Calculation takes into account irregularities such as daylight savings time and leap years. Unlike most [Dates](../../variable-data-types/the-date-variable-data-type), **delta** does not express a valid date.

#### Examples

Assume the following examples have access to the following Date values:

```javascript
example_date1 = {  
 "day": 10  
 "month": 7  
 "year": 2018  
}  
  
example_date2 = {  
 "day": 26  
 "month": 4  
 "year": 2021  
}
```

The following example returns the the number of total days, total months, and total years between **example\_date1** and **example\_date2**. Note that the values associated with "day" and "month" are too large to be valid values describing a real [Date](../../variable-data-types/the-date-variable-data-type); rather, the describe the total number of days and months (respectively) between the two given Dates:

```javascript
DATE_DELTA(example_date1, example_date2) = {  
 "day": 1021,  
 "month": 33  
 "year": 2  
}
```

DATE\_DELTA returns the absolute difference between the given Dates; it does not matter which is given first. The following example returns the the number of days, months, and years between **example\_date2** and **example\_date1**; note that the output is the same as the above example, even though the Date values are given in reverse order:

```javascript
DATE_DELTA(example_date2, example_date1) = {  
"day": 1021,  
"month": 33  
"year": 2  
}
```

#### Discussion

The Date returned by DATE\_DELTA does not contain conventional Date information; while it is technically possible to use it as Date input in functions such as [FORMAT\_DATE](format_date) or [ISO\_WEEK](format_date), the output returned in such cases will not be meaningful. To avoid such confusion, it is best practice to use DATE\_DELTA in tandem with the [DAY](day), [MONTH](month), or [YEAR](year) function, like so:

```javascript
DAY(DATE_DELTA(date1, date2)) -> day_delta
```

```javascript
MONTH(DATE_DELTA(date1, date2)) -> month_delta
```

```javascript
YEAR(DATE_DELTA(date1, date2)) -> year_delta
```

This returns a single [Number](../../variable-data-types/the-number-variable-data-type): the days, months, or years, respectively, between the two dates. &#x20;

Assume the following examples have access to **example\_date1** and **example\_date2** from the Examples section. The isolated difference between days, months, and years (respectively) between them can be found as follows:

```javascript
DAY(DATE_DELTA(example_date1, example_date2)) -> 1021
```

```javascript
MONTH(DATE_DELTA(example_date1, example_date2)) -> 33
```

```javascript
YEAR(DATE_DELTA(example_date1, example_date2)) -> 2
```
