TO_DATE

Syntax

TO_DATE
(
  str  IN text
)
RETURNS timestamp;

TO_DATE
(
  str  IN text,
  fmt  IN text
)
RETURNS timestamp;

TO_DATE
(
  num  IN integer,
  fmt  IN text
)
RETURNS timestamp;

Overview

The TO_DATE function converts text (or integer values converted to strings) to TIMESTAMP(0)(date to hours, minutes, and seconds without milliseconds) values in Oracle style date/time format.

If a format model (FMT) is provided, the date is interpreted according to that format; if not, it is converted according to the default format.

Returns NULL if an empty string is keyed in.

Unlike Oracle, it doesn't accept variables of type date to preserve type safety.

Parameter

Parameter
Description

str

text type; String containing date and time information. If it is an empty string, it is treated as NULL.

num

integer type; Integer value that is internally converted to a string and interpreted as a date.

fmt

text type; Format model that specifies the date/time format of the input string.

For example, use ‘YYYY-MM-DD HH24:MI:SS’.

For supported format models, refer to the PG official documentationarrow-up-right.

Example

Last updated