大网数据广告活动
数据库部署与 SQL 参考

StarRocks 中文参考:to_tera_timestamp

· 52CE 我爱测

# to_tera_timestamp 根据指定的格式解析输入的时间日期字符串,并转换为 DATETIME 类型的值。 ## 语法 ## 参数说明 - :待转换的时间表达式,取值必须是 VARCHAR 类型。 - :日期时间格式,用于解析和转换输入的字符串。 必须与 匹配,否则返回 NULL。如果 为无效值,返回报错。 有关返回格式中各元素的含义介绍,参见下表。 | **Element** | **Description** | | -

to_tera_timestamp

根据指定的格式解析输入的时间日期字符串,并转换为 DATETIME 类型的值。

语法

DATETIME to_tera_timestamp(VARCHAR str, VARCHAR format)

参数说明

  • str:待转换的时间表达式,取值必须是 VARCHAR 类型。

  • format:日期时间格式,用于解析和转换输入的字符串。format 必须与 str 匹配,否则返回 NULL。如果 format 为无效值,返回报错。

    有关返回格式中各元素的含义介绍,参见下表。

Element Description
[ \r \n \t - / , . ;] 标点类符号,忽略。
dd 代表日期 (1 - 31)
hh 代表小时,采用十二小时制 (1 - 12)
hh24 代表小时,采用二十四小时制 (0 - 23)
mi 代表分钟 (0 - 59)
mm 代表月份 (01 - 12)
ss 代表秒 (0 - 59)
yyyy 代表四位数的年份。
yy 代表两位数的年份。
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

本文来自 StarRocks 文档贡献者,按 Apache 2.0 整理版式与相对链接,保留正文与代码。图示请参阅原文。作者与贡献记录。

资料来源与适用范围

资料来源
StarRocks 文档贡献者
适用范围
main 文档快照(2026-11-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-16
授权说明
Apache 2.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。