# to_timestamp

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: to_timestamp
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: sql/sql-functions/timestamp-functions/to-timestamp
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/timestamp-functions/to-timestamp.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/timestamp-functions/to-timestamp.adoc
description: The `to_timestamp()` function converts a string into a timestamp based on the provided format.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/timestamp-functions/to-timestamp.md -->

The `to_timestamp()` function converts a string into a timestamp based on the provided format. It returns a `TIMESTAMP WITH TIME ZONE` type.

## [](#syntax)Syntax

The syntax for using the `to_timestamp()` function is:

```sql
SELECT TO_TIMESTAMP('source', 'format');
```

-   `source`: The date/time value to convert, provided as a text string (`YYYY-MM-DD HH:MM:SS`) that is parsed into a timestamp.

-   `format`: The format of the input string.


> 📝 **NOTE**
>
> If the source string is `NULL`, `to_timestamp` returns `NULL` instead of raising an error. This behavior is compatible with PostgreSQL.

## [](#format)Format

Format string support these template patterns (can be lowercase):

| Pattern | Description | Detail |
| --- | --- | --- |
| YYYY | Year (1–9999) | The lowest possible value is 1 AD.0001 is 1.1 is 1. |
| MM | Month number (1–12) | Up to 2 digits.01 is 1.1 is 1. |
| DD | Day of month (1–31) | Up to 2 digits.01 is 1.1 is 1. |
| HH | Hour of day (1–12) | Up to 2 digits.01 is 1.1 is 1. |
| HH12 | Hour of day (1–12) | Up to 2 digits.01 is 1.1 is 1. |
| HH24 | Hour of day (0–23) | Up to 2 digits.01 is 1.1 is 1. |
| MI | Minute (0–59) | Up to 2 digits.01 is 1.1 is 1. |
| SS | Second (0–59) | Up to 2 digits.01 is 1.1 is 1. |
| MS | Millisecond (0–999) | Up to 3 digits.001 is 1 millisecond.1 is 100 milliseconds. |
| US | Microsecond (0–999999) | Up to 6 digits.000001 is 1 microsecond.1 is 100000 microseconds. |
| AM, am, PM or pm | Meridiem indicator | Without periods. |
| A.M., a.m., P.M. or p.m. | Meridiem indicator | With periods. |

## [](#examples)Examples

### [](#timestamp-into-yyyy-mm-dd-hh24mi)Timestamp into YYYY-MM-DD HH24:MI

The `to_timestamp()` function converts the provided string into a timestamp with the format `YYYY-MM-DD HH24:MI`.

```sql
select TO_TIMESTAMP('2020-03-04 14:30', 'YYYY-MM-DD HH24:MI');
```

The output is a timestamp with a timezone.

```sql
        to_timestamp
-------------------------------
 2020-03-04 14:30:00.000000+00
```

### [](#timestamp-into-mm-dd-hh12mi)Timestamp into MM-DD HH12:MI

The `to_timestamp()` function converts the provided string into a timestamp with the format `MM-DD HH12:MI`.

```sql
select TO_TIMESTAMP('3-04 02:30', 'MM-DD HH12:MI');
```

The output is a timestamp with a timezone.

```sql
       to_timestamp
----------------------------
 1-03-04 02:30:00.000000+00
```

### [](#timestamp-into-yyyy-mm-hh12miampm)Timestamp into YYYY-MM HH12:MI(AM/PM)

The `to_timestamp()` function converts the provided string into a timestamp with the format `YYYY-MM HH12:MI` with meridiem indicator (AM/PM).

**Request 1**

```sql
select TO_TIMESTAMP('2020-02 12:30AM', 'YYYY-MM HH12:MIPM');
```

**Request 2**

```sql
select TO_TIMESTAMP('2020-02 12:30AM', 'YYYY-MM HH:MIAM');
```

The output of both requests is the same. It changes the time into a 12-hour format, resulting in **12:30** being adjusted to **00:30**.

```sql
         to_timestamp
-------------------------------
 2020-02-01 00:30:00.000000+00
```

### [](#timestamp-into-yyyy-mm-dd-hh24miss-ms-us)Timestamp into YYYY-MM-DD HH24:MI:SS.MS.US

The `to_timestamp()` function converts the provided string into a timestamp with `YYYY-MM-DD HH24:MI:SS.MS.US` format.

```sql
select TO_TIMESTAMP('1960-01-31 15:12:02.020.001230', 'YYYY-MM-DD HH24:MI:SS.MS.US');
```

The output is a timestamp with milliseconds and microseconds.

```sql
        to_timestamp
-------------------------------
 1960-01-31 15:12:02.021230+00
```

### [](#timestamp-into-yyyy-mm-dd-hh24miss-ms)Timestamp into YYYY-MM-DD HH24:MI:SS.MS

The `to_timestamp()` function converts the provided string into a timestamp with `YYYY-MM-DD HH24:MI:SS.MS` format.

```sql
select TO_TIMESTAMP('1960-01-31 15:12:02.02', 'YYYY-MM-DD HH24:MI:SS.MS');
```

The output is a timestamp with milliseconds.

```sql
        to_timestamp
-------------------------------
 1960-01-31 15:12:02.020000+00
```