---
title: 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.
url: https://coralogix.com/docs/dataprime/language-reference/functions-reference/time/tounixtime/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-10-21'
---

# `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://coralogix.com/docs/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

}
```
