> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TO_TIME

> Converts time text to a TIME value using a Spark-style format supplied for each row.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

NULL value or NULL format yields NULL; non-NULL text that matches no pattern raises an error.

## Syntax

### Format supplied for each row

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
to_time(value, format_column)
```

Calls that evaluate time text with an omitted or constant format currently fail with a time-precision error. Use a format column that varies by row, as in the example below.

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING | Yes | Time text. |
| format\_column | STRING | Yes | A format column that varies by row, such as HH:mm:ss or HH:mm. Omitted or constant formats currently fail for runtime input. |

## Returns

* Type: TIME with microsecond precision
* NULL behavior: NULL value or NULL format yields NULL; non-NULL text that matches no pattern raises an error.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Exact result | Yes |

## Usage notes

* The format can vary by row, such as `HH:mm:ss` for one row and `HH:mm` for another.
* Square brackets mark optional parts of a pattern, such as `HH:mm[:ss]`.

## Examples

### Parse rows with different time formats

The first row includes seconds; the second omits them, so its seconds are 00.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH t AS (
  SELECT id,
    CASE WHEN id = 0 THEN '10:30:45' ELSE '09:15' END AS v,
    CASE WHEN id = 0 THEN 'HH:mm:ss' ELSE 'HH:mm' END AS f
  FROM range(0, 2)
)
SELECT to_time(v, f) AS result
FROM t
ORDER BY id NULLS LAST;
```

| result |
| - |
| 10:30:45 |
| 09:15:00 |

### Parse 12-hour times with AM and PM

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH sample AS (
  SELECT id,
    CASE WHEN id = 0 THEN '11:05 PM' ELSE '08:15:30 AM' END AS time_text,
    CASE WHEN id = 0 THEN 'hh:mm a' ELSE 'hh:mm:ss a' END AS time_format
  FROM range(0, 2)
)
SELECT to_time(time_text, time_format) AS parsed FROM sample ORDER BY id;
```

| parsed |
| - |
| 23:05:00 |
| 08:15:30 |

## Limitations

* Calls that evaluate time text at runtime with an omitted or constant format currently fail with a time-precision error. Use the varying-format form shown in the example.
* Optional format sections expand to at most 256 candidate patterns. A value requiring a candidate outside that limit will not parse.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.