## Syntax
```mermaid
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
Start((START)) --> TO_DATE[TO_DATE]:::quoted
TO_DATE --> End((END))
```
## Purpose
The `TO_DATE` SQL function casts a value into a `datetime`. Non-castable values raise an error; prevent such an error by first checking the value using [[IS_DATE]].
Parameters:
- Input (`ANY`): value to cast to `datetime` if possible.
- Format (optional, `varchar2`): format mask. Defaults to configured date/time format. The list of format masks is available in [[Format Masks]].
Returns: the input cast as a `datetime`.
## Examples
The following example casts `'20190101'` to a `datetime` using a format mask:
```sql
select to_date('20190101', 'YYYYMMDD')
--------------------
01-01-2019 00:00:00
```
The following example casts an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) text to a `datetime` using the default format:
```sql
select to_date('2016-12-31T12:34:56')
--------------------
31-12-2016 12:34:56
```