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

# weeks_diff

> 计算开始时间和结束时间相差的周数，精确到周。

计算开始时间和结束时间相差几周（`expr1` - `expr2`），结果精确到周。

## 语法

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

## 参数说明

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

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

## 返回值说明

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

## 示例

```Plain Text theme={null}
select weeks_diff('2010-11-30 23:59:59', '2010-1-1 23:59:59');
+--------------------------------------------------------+
| weeks_diff('2010-11-30 23:59:59', '2010-1-1 23:59:59') |
+--------------------------------------------------------+
|                                                     47 |
+--------------------------------------------------------+

select weeks_diff(current_time(), '2010-11-30 23:59:59');
+---------------------------------------------------+
| weeks_diff(current_time(), '2010-11-30 23:59:59') |
+---------------------------------------------------+
|                                               619 |
+---------------------------------------------------+

select weeks_diff('2010-11-30 23:59:59', '2010-11-24 23:59:59');
+----------------------------------------------------------+
| weeks_diff('2010-11-30 23:59:59', '2010-11-24 23:59:59') |
+----------------------------------------------------------+
|                                                        0 |
+----------------------------------------------------------+
```


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