> ## 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_DATE

> Converts a value to a date.

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

With one argument, NULL input returns NULL. Invalid text in AUTO mode returns NULL when ANSI mode is off and raises an error when ANSI mode is on. An explicit constant NULL format raises an error. Avoid NULL values in a format column; their behavior is not reliable.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
to_date(value [, format])
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING, DATE, TIMESTAMP or INTEGER year | Yes | Value to convert. |
| format | STRING | No | Explicit string parsing pattern. Default: Automatic parsing when omitted. |

## Returns

* Type: DATE
* NULL behavior: With one argument, NULL input returns NULL. Invalid text in AUTO mode returns NULL when ANSI mode is off and raises an error when ANSI mode is on. An explicit constant NULL format raises an error. Avoid NULL values in a format column; their behavior is not reliable.

## Properties

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

## Usage notes

* INTEGER and BIGINT inputs are interpreted as calendar years, not seconds since the Unix epoch.
* Four-to-seven digit all-numeric strings denote January 1 of a year. Eight-digit YYYYMMDD strings are not silently accepted.
* With an explicit format, the input is parsed using that format.
* AUTO parsing and explicit-format parsing have different error rules. See NULL behavior above. ANSI mode is off by default.

## Examples

### Basic example 1

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT to_date('2024-03-15') AS result;
```

| result |
| - |
| 2024-03-15 |

### Basic example 2

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT to_date(2024) AS result;
```

| result |
| - |
| 2024-01-01 |

## Limitations

* Supply one or two arguments. Multiple alternative format strings are not supported.
* Explicit-format parsing errors are returned to the caller. A constant NULL format can raise 'requires at least one non-NULL format'. Avoid NULL values in a format column; their behavior is not reliable.


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