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

# str2date

> 按照指定格式将字符串转换为 DATE 类型的值。

按照 `format` 指定的格式将 `str` 转换为 DATE 类型的值。如果转换结果不对，返回 NULL。

该函数与 [str\_to\_date](/documents/cn/4.2/sql-reference/sql-functions/date-time-functions/str_to_date.md) 函数功能相同，只是返回值数据类型不同。

## 语法

```Haskell theme={null}
DATE str2date(VARCHAR str, VARCHAR format);
```

## 参数说明

`str`: 要转换的时间字符串，支持的数据类型为 VARCHAR。

`format`: 指定的时间格式，支持的数据类型为 VARCHAR。支持的时间格式与 [date\_format](/documents/cn/4.2/sql-reference/sql-functions/date-time-functions/date_format.md) 函数一致。

## 返回值说明

返回值的数据类型为 DATE，精确到年-月-日。

## 示例

```Plain theme={null}
select str2date('2010-11-30 23:59:59', '%Y-%m-%d %H:%i:%s');
+------------------------------------------------------+
| str2date('2010-11-30 23:59:59', '%Y-%m-%d %H:%i:%s') |
+------------------------------------------------------+
| 2010-11-30                                           |
+------------------------------------------------------+
1 row in set (0.01 sec)
```


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