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

# year

> 返回指定日期中的年份，范围1000到9999。

返回指定日期中的年份。

## 语法

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

## 参数说明

`date`：必填。支持 DATE 和 DATETIME 类型。

## 返回值说明

返回 INT 类型的值，范围 1000\~9999。
此函数会对整数和字符串类型的输入进行隐式转换，如果未能从输入中解析出合法年份，如 `year('string')`，则返回 NULL。如果输入数据类型非法，如 `year(3.1415)`，则返回报错。

## 示例

示例一：返回 '1987-01-01' 中的年份 `1987`。

```Plain Text theme={null}

select year('1987-01-01');
+--------------------+
| year('1987-01-01') |
+--------------------+
|               1987 |
+--------------------+
1 row in set (0.00 sec)
```

示例二：返回当前年份。

```Plain Text theme={null}
select year(now());
+-------------+
| year(now()) |
+-------------+
|        2022 |
+-------------+
1 row in set (0.00 sec)
```


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