TO_DATE Function

The TO_DATE function converts a character string to a DATETIME value. The function evaluates the char_expression first argument as a date, according to the date format that the format_string second argument specifies, and returns the equivalent date.

If char_expression is NULL, then a NULL value is returned.

Any argument to the TO_DATE function must be of a built-in data type.

If you omit the format_string parameter, the TO_DATE function applies the default DATETIME format to the DATETIME value. The default DATETIME format is specified by the GL_DATETIME environment variable.

In the following example, the user wants to convert a character string to a DATETIME value in order to update the begin_date column of the tab1 table with the converted value. The begin_date column is defined as a DATETIME YEAR TO SECOND data type. The user uses an UPDATE statement that contains a TO_DATE function to accomplish this result:
UPDATE tab1
  SET begin_date = TO_DATE('Wednesday July 25, 2007 18:45',
  '%A %B %d, %Y %R');

The format_string parameter in this example tells the TO_DATE function how to format the converted character string in the begin_date column. For a table that shows the effect of each format symbol in this format string, see TO_CHAR Function.