Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Fparseinterval.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Fparseinterval.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `parseInterval`

## Description

Returns an interval parsed from a string representation such as `2d` or `35m10s`, enabling calculations with durations.

A valid string must follow these rules:

* Format: `NdNhNmNsNmsNusNns` where `N` is a non-negative integer
* At least one time unit must be present
* No unit may appear more than once (`1d2d` is invalid)
* Units must appear in descending order (days → nanoseconds). `1d1s` is valid; `1s1d` is not
* A leading `-` is allowed to indicate a negative interval (the only valid position for `-`)
* If the format is invalid, the function returns `null`

## Syntax

Like many functions in DataPrime, `parseInterval` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
parseInterval(string: string): interval
```

```
(string: string).parseInterval(): interval
```

## Arguments

| Name     | Type     | Required | Description                          |
| -------- | -------- | -------- | ------------------------------------ |
| `string` | `string` | **true** | The string to parse into an interval |

## Example

**Use case: Parse an interval string and add it to a timestamp**

A log includes a timestamp and a `completed_in` field with a duration string. Parse the string to an interval, then add it to the timestamp to calculate the job’s completion time.

```
{

  "timestamp": 1728763337,

  "job_name": "BUILD_VIDEO",

  "completed_in": "35m10s"

}
```

### Example query

* Function notation
* Method notation

```
create completed_time from addTime(timestamp, parseInterval(completed_in))
```

```
create completed_time from timestamp.addTime(completed_in.parseInterval())
```

### Example output

```
{

  "timestamp": 1728763337,

  "job_name": "BUILD_VIDEO",

  "completed_in": "35m10s",

  "completed_time": 1728765447

}
```
