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

# timediff

> 返回两个DATETIME类型值之间的差值。

返回两个 DATETIME 类型值之间的差值。

## 语法

```Haskell theme={null}
TIME TIMEDIFF(DATETIME expr1, DATETIME expr2)`
```

## 参数说明

`expr1`: 结束时间，支持的数据类型为 DATETIME。

`expr2`: 开始时间，支持的数据类型为 DATETIME。

## 返回值说明

返回值的数据类型为 TIME 类型。如果日期不存在，则返回 NULL。如果日期为 DATE 类型，则按照该日期的零点进行计算。

## 示例

```Plain Text theme={null}
SELECT TIMEDIFF(now(),utc_timestamp());
+----------------------------------+
| timediff(now(), utc_timestamp()) |
+----------------------------------+
| 08:00:00                         |
+----------------------------------+

SELECT TIMEDIFF('2019-07-11 16:59:30','2019-07-11 16:59:21');
+--------------------------------------------------------+
| timediff('2019-07-11 16:59:30', '2019-07-11 16:59:21') |
+--------------------------------------------------------+
| 00:00:09                                               |
+--------------------------------------------------------+

SELECT TIMEDIFF('2019-01-01 00:00:00', NULL);
+---------------------------------------+
| timediff('2019-01-01 00:00:00', NULL) |
+---------------------------------------+
| NULL                                  |
+---------------------------------------+
```


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