> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# to_tera_timestamp

> 根据指定格式解析时间日期字符串并转换为DATETIME值。

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

## 语法

```Haskell theme={null}
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 | 代表十二小时制里的下午。 |

## 示例

```SQL theme={null}
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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.