跳到主要内容
版本: 最新版本-3.5

to_tera_date

根据指定的格式解析日期或时间字符串,并将字符串转换为 DATE 值。

语法

DATE to_tera_date(VARCHAR str, VARCHAR format)

参数

  • str:要转换的时间表达式。它必须是 VARCHAR 类型。

  • formatstr 的日期格式说明符。它用于解析和转换输入字符串。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)
    yyyy4 位数年份。
    yy2 位数年份。
    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