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

# date

> 从日期或时间日期表达式中截取日期部分。

从日期或时间日期表达式中截取日期部分。

## 语法

```Haskell theme={null}
DATE date(DATETIME|DATE expr)
```

## 参数说明

`expr`: 日期或时间日期表达式。支持的数据类型为 DATE 或 DATETIME。

## 返回值说明

返回值的数据类型为 DATE。如果输入值为 NULL 或数据类型不合法，则返回 NULL。

## 示例

示例一：从 DATETIME 值中截取日期部分。

```Plain theme={null}
SELECT DATE("2017-12-31 11:20:59");
+-----------------------------+
| date('2017-12-31 11:20:59') |
+-----------------------------+
| 2017-12-31                  |
+-----------------------------+
1 row in set (0.05 sec)
```

示例二：从 DATE 值中截取日期部分。

```Plain theme={null}
SELECT DATE('2017-12-31');
+--------------------+
| date('2017-12-31') |
+--------------------+
| 2017-12-31         |
+--------------------+
1 row in set (0.08 sec)
```

示例三：该函数与 current\_timestamp() 函数搭配使用，截取当前时间戳中的日期部分。

```Plain theme={null}
SELECT DATE(current_timestamp());
+---------------------------+
| date(current_timestamp()) |
+---------------------------+
| 2022-11-08                |
+---------------------------+
1 row in set (0.05 sec)
```


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