Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Ftounixtime.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%2Ftounixtime.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `toUnixTime`

## Description

Returns the number of time units since the Unix epoch (`1970-01-01T00:00:00Z`) for a given timestamp.

Note

Timestamps before the epoch are represented as negative numbers.

## Syntax

Like many functions in DataPrime, `toUnixTime` 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

```
toUnixTime(timestamp: timestamp, timeUnit?: timeunit): number
```

```
(timestamp: timestamp).toUnixTime(timeUnit?: timeunit): number
```

## Arguments

| Name        | Type        | Required  | Description                                  |
| ----------- | ----------- | --------- | -------------------------------------------- |
| `timestamp` | `timestamp` | **true**  | The timestamp to convert                     |
| `timeUnit`  | `timeunit`  | **false** | The unit for the result. Defaults to `milli` |

## Example

**Use case: Convert a nanosecond timestamp into seconds for system compatibility**

A log contains a timestamp in nanoseconds. Convert it to seconds to match external system requirements.

### Example data

```
{

    "ts": 1728769618374000000

}
```

### Example query

* Function notation
* Method notation

```
create ts_seconds from toUnixTime(ts, 's')
```

```
create ts_seconds from ts.toUnixTime('s')
```

### Example output

```
{

    "ts": 1728769618374000000,

    "ts_seconds": 1728769618

}
```
