# TIME\_DELTA

**The function TIME\_DELTA returns returns the number of total hours, total minutes, total seconds, and total milliseconds between two Times.**

This function takes two [Times](../../variable-data-types/the-time-variable-data-type) as input. It returns he number of total hours, total minutes, total seconds, and total milliseconds between the two Times. This output is a is formatted like another [Time](../../variable-data-types/the-time-variable-data-type), but, unlike most [Times](../../variable-data-types/the-time-variable-data-type), it does not express a valid time of day. Calculation takes into account irregularities such as daylight savings time and leap years.

#### Declaration

```javascript
TIME_DELTA(time1, time2) -> delta
```

&#x20;

#### Parameters

**time1** (required, type: _Time_) Any time.

**time** (required, type: _Time_) Any time.

#### Return Values

**delta** (type: _Time_) The number of total hours, total minutes, total seconds, and total milliseconds between **time1** and **time2**. Calculation takes into account irregularities such as daylight savings time and leap years. Unlike most [Times](../../variable-data-types/the-time-variable-data-type), **delta** does not express a valid time of day.

#### Examples

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

```javascript
example_time1 = {  
 "hour": 12  
 "minute": 38  
 "second": 24  
 "millisecond": 0  
}  
  
example_time2 = {  
 "hour": 2  
 "minute": 10  
 "second": 4  
 "millisecond": 500  
}
```

The following example returns the the number of hours, minutes, seconds, and milliseconds between **example\_time1** and **example\_time2**. Note that the values associated with "minute", "second", and millisecond" are too large to be valid values describing a real [Time](../../variable-data-types/the-time-variable-data-type); rather, the describe the total number of minutes, seconds and milliseconds (respectively) between the two given Times:

```javascript
TIME_DELTA(example_time1, example_time2) = {  
 "hour": 10  
 "minute": 628  
 "second": 37699  
 "millisecond": 37699500  
}
```

TIME\_DELTA returns the absolute difference between the given Times; it does not matter which is given first. The following example returns the the number of hours, minutes, seconds, and milliseconds between **example\_time2** and **example\_time1**; note that the output is the same as the above example, even though the Time values are given in reverse order:

```javascript
TIME_DELTA(example_time2, example_time1) = {  
 "hour": 10  
 "minute": 628  
 "second": 37699  
 "millisecond": 37699500  
}
```

&#x20;

#### Discussion

The Time returned by TIME\_DELTA does not contain conventional TIME information; while it is technically possible to use it as TIME input in functions such as [FORMAT\_TIME](format_time), the output returned in such cases will not be meaningful. To avoid such confusion, it is best practice to use TIME\_DELTA in tandem with the [HOUR](hour), [MINUTE](minute), or [SECOND](second) function. (There is no analogous MILLISECOND function; such small differences in time are effectively negligible in the context of real-world apps.) Examples can be found below:&#x20;

```javascript
HOUR(TIME_DELTA(time1, time2)) -> hour_delta
```

```javascript
MINUTE(TIME_DELTA(time1, time2)) -> minute_delta
```

```javascript
SECOND(TIME_DELTA(time1, time2)) -> second_delta
```

This returns a single [Number](../../variable-data-types/the-number-variable-data-type): the hours, minutes, or seconds, respectively, between the two times. &#x20;

Assume the following examples have access to **example\_time1** and **example\_time2** from the Examples section. The isolated difference between hours, minutes, or seconds (respectively) between them can be found as follows:

```javascript
HOUR(TIME_DELTA(example_time1, example_time2)) -> 10
```

```javascript
MINUTE(TIME_DELTA(example_time1, example_time2)) -> 628
```

```javascript
SECOND(TIME_DELTA(example_time1, example_time2)) -> 37699
```
