to_tera_date
根据指定的格式解析日期或时间字符串,并将字符串转换为 DATE 值。
语法
DATE to_tera_date(VARCHAR str, VARCHAR format)
参数
-
str
:要转换的时间表达式。它必须是 VARCHAR 类型。 -
format
:str
的日期格式说明符。它用于解析和转换输入字符串。format
必须与string
匹配。否则,返回 NULL。如果format
无效,则返回错误。下表描述了格式元素。
Element 描述 [ \r \n \t - / , . ;] 在转换中忽略的标点符号 dd 月份中的日期 (1 - 31) hh 一天中的小时 (1 - 12) hh24 一天中的小时 (0 - 23) mi 分钟 (0 - 59) mm 月份 (01 - 12) ss 秒 (0 - 59) yyyy 4 位数年份。 yy 2 位数年份。 am 子午线指示器。 pm 子午线指示器。
示例
select to_tera_date("1988/04/08","yyyy/mm/dd");
+------------------------------------------+
| to_tera_date('1988/04/08', 'yyyy/mm/dd') |
+------------------------------------------+
| 1988-04-08 |
+------------------------------------------+
select to_tera_date("04-08-1988","mm-dd-yyyy");
+------------------------------------------+
| to_tera_date('04-08-1988', 'mm-dd-yyyy') |
+------------------------------------------+
| 1988-04-08 |
+------------------------------------------+
select to_tera_date(";198804:08",";yyyymm:dd");
+------------------------------------------+
| to_tera_date(';198804:08', ';yyyymm:dd') |
+------------------------------------------+
| 1988-04-08 |
+------------------------------------------+
select to_tera_date("2020-02-02 00:00:00", "yyyy-mm-dd");
+---------------------------------------------------+
| to_tera_date('2020-02-02 00:00:00', 'yyyy-mm-dd') |
+---------------------------------------------------+
| 2020-02-02 |
+---------------------------------------------------+
-- The input is year and does not contain the month or date part. The first day in that year is returned.
select to_tera_date("1988","yyyy");
+------------------------------+
| to_tera_date('1988', 'yyyy') |
+------------------------------+
| 1988-01-01 |
+------------------------------+
关键词
TO_TERA_DATE