## 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 (`varchar2`): format mask. Optional; 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`: ```sql select is_date('20190101', 'YYYYMMDD') -------------------- 01-01-2019 00:00:00 ```