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

# days_diff

> 计算两个日期表达式的天数差（expr1 − expr2），精确到天。

计算开始时间和结束时间相差几天 （`expr1` - `expr2`），结果精确到天。此函数与 [datediff](/documents/cn/4.2/sql-reference/sql-functions/date-time-functions/datediff.md) 的区别是：

| 函数名 | 行为 | 例子 |
| - | - | - |
| days\_diff | 对日期的判断精确到秒级，并向下取整数。 | '2020-12-25 23:00:00' 与 '2020-12-24 23:00:01' 的 days\_diff 为 0。 |
| datediff | 对日期的判断精确到天级。 | '2020-12-25 23:00:00' 与 '2020-12-24 23:00:01' 的 datediff 为 1。 |

## 语法

```Haskell theme={null}
BIGINT days_diff(DATETIME expr1,DATETIME expr2);
```

## 参数说明

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

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

## 返回值说明

返回值的数据类型为 BIGINT。如果日期不存在，则返回 NULL。如果相差不满一天，则返回 0。

## 示例

```Plain Text theme={null}
select days_diff('2010-11-30 23:00:00', '2010-11-29 23:00:00');
+---------------------------------------------------------+
| days_diff('2010-11-30 23:00:00', '2010-11-29 23:00:00') |
+---------------------------------------------------------+
| 1                                                       |
+---------------------------------------------------------+

select days_diff('2010-11-30 23:00:00', '2010-11-29 23:10:00');
+---------------------------------------------------------+
| days_diff('2010-11-30 23:00:00', '2010-11-29 23:10:00') |
+---------------------------------------------------------+
| 0                                                       |
+---------------------------------------------------------+
```


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