# 系统内置变量

Recurve 产品内提供多种内置变量，可以基于调度时间定义数据范围

## 内置变量

<table><thead><tr><th width="240">变量名称</th><th width="230">类型</th><th width="417">描述</th></tr></thead><tbody><tr><td><code>data_interval_start</code></td><td>datetime.datetime</td><td>表示当前调度批次所处理的数据范围的开始时间，结合调度周期来确定。</td></tr><tr><td><code>data_interval_end</code></td><td>datetime.datetime</td><td>表示当前调度批次所处理的数据范围的结束时间，结合调度周期来确定。</td></tr><tr><td><code>logical_date</code></td><td>datetime.datetime</td><td>表示调度批次的逻辑时间，通常与 <code>data_interval_end</code> 相等</td></tr><tr><td><code>dt</code></td><td>datetime.date</td><td><code>logical_date</code>的日期部分</td></tr><tr><td><code>yesterday</code></td><td>datetime.datetime</td><td><code>logical_date</code>的前一天，在日度任务中有用，其他周期不要使用</td></tr><tr><td><code>yesterday_dt</code></td><td>datetime.date</td><td><code>yesterday</code>的日期部分</td></tr><tr><td><code>tomorrow</code></td><td>datetime.datetime</td><td><code>logical_date</code> 的后一天，在日度任务中有用，其他周期不要使用</td></tr><tr><td><code>tomorrow_dt</code></td><td>datetime.date</td><td><code>tomorrow</code> 的日期部分</td></tr></tbody></table>

以每天 10 点运行的日度任务为例，在 2025-02-01 这一天，各个变量的值为：

* `data_interval_start`：是 T-1 的 10 点，即 `2025-01-31 10:00:00`
* `data_interval_end`：是 T 的 10 点，即 `2025-02-01 10:00:00`（同理，如果是周度、月度的，`data_interval_end` 就是本次调度度的逻辑时间(不是系统时间)，`data_interval_start` 就是上一个周期）
* `logical_date`：`2025-02-01 10:00:00`
* `dt`：`2025-02-01`
* `yesterday`:  `2025-01-31 10:00:00`
* `yesterday_dt`:  `2025-01-31`
* `tomorrow`: `2025-02-02 10:00:00`
* `tomorrow_dt`: `2025-02-02`

以每月 1 号 10点运行月度任务为例，在 2025-02-01 这一天，各个变量的值为：

* `data_interval_start`：表示 1 月 1 日 10 点，即 `2025-01-01 10:00:00`
* `data_interval_end`：`2025-02-01 10:00:00`
* `logical_date`：`2025-02-01 10:00:00`
* `dt`：`2025-02-01`

以下几个变量是方便在日度任务中使用的，在月度（及其他）任务中仍然有值，但是通常没有实际用途，建议**不要使用**。

* `yesterday`:  `2025-01-31 10:00:00`
* `yesterday_dt`:  `2025-01-31`
* `tomorrow`: `2025-02-02 10:00:00`
* `tomorrow_dt`: `2025-02-02`

## 使用系统变量

你可以在数据模型、高级管道中使用这些系统变量，在代码中使用 `{{ var("变量名称") }}`

例如：在数据建模中增量更新当天的数据

```sql
 select ...
 from {{ source("jaffle_shop", "raw_orders") }}
 where dt = {{ var('dt') }}
```

通常建议使用 `data_interval_start` 和 `data_interval_end` 来圈定数据范围，因为能根据调度周期自动灵活调整。可以使用这两个时间进行演变，得到其他格式，如：

<pre class="language-django"><code class="lang-django"><strong># 获取日期部分，返回 datetime.date 类型，date(2025, 1, 1)
</strong><strong>{{ var("data_interval_start").date() }}
</strong><strong>
</strong><strong># 格式化为 `20250101`，结果是个字符串
</strong>{{ var("data_interval_start").strftime("%Y%m%d") }}
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.reorc.com/cn-reorc-help-center/advanced_usage/bian-liang/xi-tong-nei-zhi-bian-liang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
