Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Fparsetimestamp.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Fparsetimestamp.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `parseTimestamp`

## Description

Returns a parsed timestamp from a date or time string, enabling use of DataPrime's time functions.

Note

If the string cannot be parsed (for example, if it does not match the expected format), the function returns `null`.

## Syntax

Like many functions in DataPrime, `parseTimestamp` supports<!-- --> [two notations](https://coralogix.com/docs/docs/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

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

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

## Arguments

| Name     | Type     | Required  | Description                                                                                             |
| -------- | -------- | --------- | ------------------------------------------------------------------------------------------------------- |
| `string` | `string` | **true**  | The string to parse into a timestamp                                                                    |
| `format` | `string` | **false** | The format of the input string. Defaults to `auto`, which attempts to match against well-known formats. |
| `tz`     | `string` | **false** | A valid time zone string                                                                                |

## Example 1

**Use case: Parse a simple date string using default format**

### Example query

* Function notation
* Method notation

```
choose parseTimestamp('2023-04-05') as ts
```

```
choose '2023-04-05'.parseTimestamp() as ts
```

### Example output

```
{

    "ts": 1680652800000000000

}
```

## Example 2

**Use case: Parse a US-style date**

### Example query

* Function notation
* Method notation

```
choose parseTimestamp('04/05/23', '%D') as ts
```

```
choose '04/05/23'.parseTimestamp('%D') as ts
```

### Example output

```
{

    "ts": 1680652800000000000

}
```

## Example 3

**Use case 3: Parse date and time with units**

### Example query

* Function notation
* Method notation

```
choose parseTimestamp('2023-04-05 16h07m', '%F %Hh%Mm') as ts
```

```
choose '2023-04-05 16h07m'.parseTimestamp('%F %Hh%Mm') as ts
```

### Example output

```
{

    "ts": 1680710820000000000

}
```

## Example 4

**Use case 4: Parse a Unix timestamp in seconds**

### Example query

* Function notation
* Method notation

```
choose parseTimestamp('1680710853', 'timestamp_second') as ts
```

```
choose '1680710853'.parseTimestamp('timestamp_second') as ts
```

### Example output

```
{

    "ts": 1680710853000000000

}
```

## Example 5

**Use case 5: Parse inconsistent formats with multiple options**

Some logs contain timestamps in different formats. Provide a `|`-separated list of formats to handle them all.

### Example data

```
{ "ts": "1680710853123", "app": "app1" },

{ "ts": "2023-04-05", "app": "app2" },

{ "ts": "2023-04-05T16:07:33.123Z", "app": "app3" }
```

### Example query

* Function notation
* Method notation

```
create ts_parsed from parseTimestamp(ts, 'timestamp_second|%Y-%m-%d|iso8601')
```

```
create ts_parsed from ts.parseTimestamp('timestamp_second|%Y-%m-%d|iso8601')
```

### Example output

```
{ "ts": "1680710853123", "app": "app1", "ts_parsed": 1680710853123000000 },

{ "ts": "2023-04-05", "app": "app2", "ts_parsed": 1680652800000000000 },

{ "ts": "2023-04-05T16:07:33.123Z", "app": "app3", "ts_parsed": 1680710853123000000 }
```
