Updated on 2026-11-06 GMT+08:00

to_date1

The to_date1 function is used to convert a string in the specified format to a date value.

Similar function: to_date. The to_date function returns the year, month, and day from a time and does not support specifying the target date format.

Syntax

to_date1(string date, string format)

Parameters

Table 1 Parameter descriptions

Parameter

Mandatory

Type

Description

date

Yes

STRING

The string to be converted.

Formats:
  • yyyy-mm-dd
  • yyyy-mm-dd hh:mi:ss
  • yyyy-mm-dd hh:mi:ss.ff3

format

Yes

STRING

The target date format for conversion.

A STRING type constant. Extended date formats are not supported.

The format is a combination of time units representing year, month, day, hour, minute, and second, along with any characters.

  • yyyy indicates year.
  • mm indicates month.
  • dd indicates day.
  • hh indicates hour.
  • mi indicates minute.
  • ss indicates second.

Return Values

Returns a date string of type STRING in the format yyyy-mm-dd hh:mi:ss (including hours, minutes, and seconds).

  • If date is not of type DATE or STRING, an error is returned with the message "data type mismatch".
  • If date is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
  • If the date value is NULL, NULL is returned.
  • If the format value is NULL, a date value in the format yyyy-mm-dd is returned.

Example Code

Returns 2023-08-16 10:54:36.

select to_date1('2023-08-16 10:54:36','yyyy-mm-dd hh:mi:ss');

Returns 2023-08-16 00:00:00.

select to_date1('2023-08-16','yyyy-mm-dd');

Returns NULL.

select to_date1(null);

Returns 2023-08-16.

select to_date1('2023-08-16 10:54:36');