Outdated Version

You are viewing an older version of this section. View current production version.

TO_TIMESTAMP

Converts a string to a TIMESTAMP(6) value.

Syntax

TO_TIMESTAMP ( convert_from_value, convert_from_format )

Arguments

convert_from_value

A string specifying the value to convert from.

convert_from_format

A format string, comprised of one or more format specifiers.

Info

convert_from_format may contain characters that are not format specifiers. These characters must appear in the same position in convert_from_value; otherwise, TO_TIMESTAMP will return NULL.

Example

In the following example, the string The date and time are is included in the same location in both arguments to TO_TIMESTAMP, allowing the function to successfully return a TIMESTAMP(6) value. If this string were to be excluded from both arguments, the output would remain the same as shown below.

SELECT TO_TIMESTAMP('The date and time are 01/01/2018 2:30:15.123456',
	'The date and time are MM/DD/YYYY HH:MI:SS.FF6') AS result;

Output:

+----------------------------+
| result                     |
+----------------------------+
| 2018-01-01 02:30:15.123456 |
+----------------------------+