# `addTime`

## Description

Returns a new timestamp by adding an interval to an existing timestamp.

Both `timestamp` and `interval` are first-class types in DataPrime, so ensure that the correct types are passed.

Note

Negative intervals are supported and act as subtraction. For example, adding `-1h` to a timestamp subtracts one hour.

## Syntax

Like many functions in DataPrime, `addTime` supports [two notations](https://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

```dataprime
addTime(t: timestamp, i: interval): timestamp
```

```dataprime
(t: timestamp).addTime(i: interval): timestamp
```

## Arguments

| Name | Type      | Required | Description                                    |
| ---- | --------- | -------- | ---------------------------------------------- |
| t    | timestamp | **true** | The base timestamp to modify                   |
| i    | interval  | **true** | The interval to add (or subtract, if negative) |

## Example

**Use case: Compute an event’s end time from its start time and duration**

A log contains a `start_timestamp` field and a `duration` field in seconds. Convert the duration to an interval, then add it to the start time to calculate the event's `end_timestamp`.

```json
{
  "start_timestamp": 1728582889,
  "duration": 120
}
```

### Example query

```dataprime
create end_timestamp from addTime(start_timestamp, duration.toInterval('s'))
```

```dataprime
create end_timestamp from start_timestamp.addTime(duration.toInterval('s'))
```

### Example output

```json
{
  "start_timestamp": 1728582889,
  "duration": 120,
  "end_timestamp": 1728583009
}
```
