invantive documentationpart of invantive cloud
Invantive Support ForumsLog In / Sign Up

TO_DATE

Syntax

%%{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, such as DD-MON-YYYY HH24:MI. Defaults to configured date/time format. The elements of a format mask are described in Format Masks; any combination of elements is available from release 28.0.

Returns: the input cast as a datetime.

Examples

The following example casts '20190101' to a datetime using a format mask:

select to_date('20190101', 'YYYYMMDD')

--------------------
01-01-2019 00:00:00

The following example casts a text with a month name and a time without seconds to a datetime:

select to_date('13-Aug-2026 12:34', 'DD-MON-YYYY HH24:MI')

--------------------
13-08-2026 12:34:00

The following example casts an ISO 8601 text to a datetime using the default format:

select to_date('2016-12-31T12:34:56')

--------------------
31-12-2016 12:34:56