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

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

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

```json
{
    "ts": 1728769618374000000
}
```

### Example query

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

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

### Example output

```json
{
    "ts": 1728769618374000000,
    "ts_seconds": 1728769618
}
```
