to_tera_timestamp
根据指定的格式解析日期或时间字符串,并将字符串转换为 DATETIME 值。
语法
DATETIME to_tera_timestamp(VARCHAR str, VARCHAR format)
参数
-
str
:要转换的时间表达式。它必须是 VARCHAR 类型。 -
format
:str
的时间格式说明符。它用于解析和转换输入字符串。format
必须与string
匹配。否则,将返回 NULL。如果format
无效,则返回错误。下表描述了格式元素。
元素 描述 [ \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_timestamp("1988/04/08","yyyy/mm/dd");
+-----------------------------------------------+
| to_tera_timestamp('1988/04/08', 'yyyy/mm/dd') |
+-----------------------------------------------+
| 1988-04-08 00:00:00 |
+-----------------------------------------------+
select to_tera_timestamp("04-08-1988","mm-dd-yyyy");
+-----------------------------------------------+
| to_tera_timestamp('04-08-1988', 'mm-dd-yyyy') |
+-----------------------------------------------+
| 1988-04-08 00:00:00 |
+-----------------------------------------------+
select to_tera_timestamp("04.1988,08","mm.yyyy,dd");
+-----------------------------------------------+
| to_tera_timestamp('04.1988,08', 'mm.yyyy,dd') |
+-----------------------------------------------+
| 1988-04-08 00:00:00 |
+-----------------------------------------------+
select to_tera_timestamp("1988/04/08 2","yyyy/mm/dd hh");
+----------------------------------------------------+
| to_tera_timestamp('1988/04/08 2', 'yyyy/mm/dd hh') |
+----------------------------------------------------+
| 1988-04-08 02:00:00 |
+----------------------------------------------------+
select to_tera_timestamp("1988/04/08 14","yyyy/mm/dd hh24");
+-------------------------------------------------------+
| to_tera_timestamp('1988/04/08 14', 'yyyy/mm/dd hh24') |
+-------------------------------------------------------+
| 1988-04-08 14:00:00 |
+-------------------------------------------------------+
select to_tera_timestamp("1988/04/08 14:15","yyyy/mm/dd hh24:mi");
+-------------------------------------------------------------+
| to_tera_timestamp('1988/04/08 14:15', 'yyyy/mm/dd hh24:mi') |
+-------------------------------------------------------------+
| 1988-04-08 14:15:00 |
+-------------------------------------------------------------+
select to_tera_timestamp("1988/04/08 2:3:4","yyyy/mm/dd hh24:mi:ss");
+----------------------------------------------------------------+
| to_tera_timestamp('1988/04/08 2:3:4', 'yyyy/mm/dd hh24:mi:ss') |
+----------------------------------------------------------------+
| 1988-04-08 02:03:04 |
+----------------------------------------------------------------+
select to_tera_timestamp("1988/04/08 02 am:3:4","yyyy/mm/dd hh am:mi:ss");
+---------------------------------------------------------------------+
| to_tera_timestamp('1988/04/08 02 am:3:4', 'yyyy/mm/dd hh am:mi:ss') |
+---------------------------------------------------------------------+
| 1988-04-08 02:03:04 |
+---------------------------------------------------------------------+
关键词
TO_TERA_TIMESTAMP