The topic describes how to use the TO_DATE function. This function converts a date value from the INT or VARCHAR data type to the DATE data type.
Syntax
Date TO_DATE(INT time)
Date TO_DATE(VARCHAR date)
Date TO_DATE(VARCHAR date,VARCHAR format)
Input parameters
Parameter | Data type | Description |
time | INT |
|
date | VARCHAR | The date. The default format is yyyy-MM-dd. |
format | VARCHAR | The date format. |
Example
Test data
Table 1 T1
date1(INT)
date2(VARCHAR)
date3(VARCHAR)
date4(VARCHAR)
date5(VARCHAR)
200
2017-09-15
20170915
09152017
092017
Test statement
SELECT TO_DATE(date1) as var1, TO_DATE(date2) as var2, TO_DATE(date3,'yyyyMMdd') as var3, TO_DATE(date4,'MMddyyyy') as var4, TO_DATE(date5,'MMyyyy') as var5 FROM T1;
Test result
var1(DATE)
var2(DATE)
var3(DATE)
var4(DATE)
var5(DATE)
1970-07-20 (Realtime Compute for Apache Flink that uses VVR 8.0.6 or later)
0200-01-01 (Realtime Compute for Apache Flink that uses a VVR version earlier than 8.0.6)
2017-09-15
2017-09-15
2017-09-15
2017-09-01
References
For more information about how to convert a date value of the VARCHAR data type into the TIMESTAMP data type based on the specified time zone, see TO_TIMESTAMP_TZ.
For more information about how the date value returns after the specified number of days is added to a date value, see DATE_ADD.