# `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/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

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

```dataprime
(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

```json
{
    "first_timestamp": 1728636298,
    "second_timestamp": 1728636358
}
```

### Example query

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

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

### Example output

```json
{
    "first_timestamp": 1728636298,
    "second_timestamp": 1728636358,
    "time_difference": 60
}
```
