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

# `abs`

## Description

Returns the absolute value of a number. Useful for computing the total difference between two values without regard to sign.

## Syntax

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

* Function notation
* Method notation

```
abs(number: number): number
```

```
(number: number).abs(): number
```

## Arguments

| Name     | Type     | Required | Description                               |
| -------- | -------- | -------- | ----------------------------------------- |
| `number` | `number` | **true** | The value to convert to a positive number |

## Example

**Use case: Calculate the difference between two timestamps** Generate a `time_difference` field based on two timestamp values. Using `abs` avoids worrying about which timestamp is greater.

### Example data

```
{

    "first_timestamp": 1728636298,

    "second_timestamp": 1728636358

}
```

### Example query

* Function notation
* Method notation

```
source logs | create time_difference from abs(first_timestamp - second_timestamp)
```

```
source logs | create time_difference from (first_timestamp - second_timestamp).abs()
```

### Example output

```
{

    "first_timestamp": 1728636298,

    "second_timestamp": 1728636358,

    "time_difference": 60

}
```
