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

# `formatTimestamp`

## Description

Returns a timestamp formatted as a string, with optional control over the output format and time zone.

## Syntax

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

```
formatTimestamp(timestamp: timestamp, format?: string, tz?: string): string
```

```
(timestamp: timestamp).formatTimestamp(format?: string, tz?: string): string
```

## Arguments

| Name        | Type        | Required  | Description                                                  |
| ----------- | ----------- | --------- | ------------------------------------------------------------ |
| `timestamp` | `timestamp` | **true**  | The timestamp to format                                      |
| `format`    | `string`    | **false** | The format specification. Defaults to `iso8601`              |
| `tz`        | `string`    | **false** | A valid time zone string (see Time Zone section for details) |

## Example 1

Print a timestamp with a +5h offset using the default format\*\*

### Example query

* Function notation
* Method notation

```
choose formatTimestamp($m.timestamp, tz='+05') as ts
```

```
choose $m.timestamp.formatTimestamp(tz='+05') as ts
```

### Example output

```
{

    "ts": "2023-08-29T19:08:37.405937400+0500"

}
```

## Example 2

**Use case 2: Print only the year and month**

### Example query

* Function notation
* Method notation

```
choose formatTimestamp($m.timestamp, '%Y-%m') as ym
```

```
choose $m.timestamp.formatTimestamp('%Y-%m') as ym
```

### Example output

```
{

    "ym": "2023-08"

}
```

## Example 3

**Use case 3: Print only the hours and minutes**

### Example query

* Function notation
* Method notation

```
choose formatTimestamp($m.timestamp, '%H:%M') as hm
```

```
choose $m.timestamp.formatTimestamp('%H:%M') as hm
```

### Example output

```
{

"hm": "14:11"

}
```

## Example 4

**Use case 4: Print a timestamp in milliseconds (13 digits)**

### Example query

* Function notation
* Method notation

```
choose formatTimestamp($m.timestamp, 'timestamp_milli') as ms
```

```
choose $m.timestamp.formatTimestamp('timestamp_milli') as ms
```

### Example output

```
{

    "ms": "1693318678696"

}
```
