# 日期时间辅助函数

> 供日期规格化、周编号和数值日期运算使用。

---

LLMS 索引： [llms.txt](/zh/llms.txt)

---

供日期规格化、周编号和数值日期运算使用。

## _ {#underscore}

| 对象签名 | 用途 | 源码定义 |
|---|---|---|
| <a id="mysql-calc-days-in-year-integer-68456ae3" href="#mysql-calc-days-in-year-integer-68456ae3">`mysql._calc_days_in_year(integer) → integer`</a> | 计算指定年份的天数。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L953-L962) |
| <a id="mysql-calc-week-pg-catalog-date-integer-68b665f1" href="#mysql-calc-week-pg-catalog-date-integer-68b665f1">`mysql._calc_week(qdate date, behavior integer) → integer[]`</a> | 按 MySQL 的周编号规则计算星期或周数。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L964-L1010) |
| <a id="mysql-calc-weekday-pg-catalog-date-boolean-7bedfe5f" href="#mysql-calc-weekday-pg-catalog-date-boolean-7bedfe5f">`mysql._calc_weekday(qdate date, sundayfirst boolean) → integer`</a> | 按 MySQL 的周编号规则计算星期或周数。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L946-L951) |
| <a id="mysql-convert-format-to-halo-for-number-datetime-pg-catalog-text-79324f0e" href="#mysql-convert-format-to-halo-for-number-datetime-pg-catalog-text-79324f0e">`mysql._convert_format_to_halo_for_number_datetime(text) → text`</a><span id="mysql-normalize-numeric-datetime-pg-catalog-text-5989e469"></span> | 整理日期时间输入，供后续转换为 text。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1467-L1501) |
| <a id="mysql-convert-format-to-halo-for-string-datetime-pg-catalog-text-16da9bf2" href="#mysql-convert-format-to-halo-for-string-datetime-pg-catalog-text-16da9bf2">`mysql._convert_format_to_halo_for_string_datetime(text) → text`</a><span id="mysql-normalize-datetime-text-pg-catalog-text-6c38ae20"></span> | 整理日期时间输入，供后续转换为 text。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1411-L1432) |
| <a id="mysql-convert-format-to-halo-for-string-number-datetime-pg-catalog-text-84d03608" href="#mysql-convert-format-to-halo-for-string-number-datetime-pg-catalog-text-84d03608">`mysql._convert_format_to_halo_for_string_number_datetime(text) → text`</a><span id="mysql-normalize-compact-datetime-text-pg-catalog-text-03daa77c"></span> | 整理日期时间输入，供后续转换为 text。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1348-L1383) |
| <a id="mysql-convert-format-to-halo-for-string-string-datetime-pg-catalog-text-5839bdfc" href="#mysql-convert-format-to-halo-for-string-string-datetime-pg-catalog-text-5839bdfc">`mysql._convert_format_to_halo_for_string_string_datetime(text) → text`</a><span id="mysql-normalize-delimited-datetime-text-pg-catalog-text-f99e41d6"></span> | 整理日期时间输入，供后续转换为 text。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1386-L1408) |
| <a id="mysql-date-padding-pg-catalog-text-f4f7aba1" href="#mysql-date-padding-pg-catalog-text-f4f7aba1">`mysql._date_padding(text) → text`</a> | 整理日期时间输入，供后续转换为 text。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L330-L361) |
| <a id="mysql-process-for-number-datetime-pg-catalog-text-177ef4a3" href="#mysql-process-for-number-datetime-pg-catalog-text-177ef4a3">`mysql._process_for_number_datetime(text) → text`</a> | 整理日期时间输入，供后续转换为 text。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1435-L1464) |
| <a id="mysql-process-for-string-number-datetime-pg-catalog-text-98976bd2" href="#mysql-process-for-string-number-datetime-pg-catalog-text-98976bd2">`mysql._process_for_string_number_datetime(text) → text`</a> | 整理日期时间输入，供后续转换为 text。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1314-L1345) |
| <a id="mysql-week-mode-integer-69224ad5" href="#mysql-week-mode-integer-69224ad5">`mysql._week_mode(mode integer) → integer`</a> | 按 MySQL 的周编号规则计算星期或周数。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L931-L944) |

## C {#c}

| 对象签名 | 用途 | 源码定义 |
|---|---|---|
| <a id="mysql-convert-to-time-format-pg-catalog-text-21c74509" href="#mysql-convert-to-time-format-pg-catalog-text-21c74509">`mysql.convert_to_time_format(text) → interval`</a> | 整理日期时间输入，供后续转换为 interval。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L647-L720) |
| <a id="mysql-curdate-add-integer-34b980fc" href="#mysql-curdate-add-integer-34b980fc">`mysql.curdate_add(integer) → integer`</a> | 对当天的 YYYYMMDD 整数值做加减运算。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L290-L303) |
| <a id="mysql-curdate-sub-integer-c6dfbfb0" href="#mysql-curdate-sub-integer-c6dfbfb0">`mysql.curdate_sub(integer) → integer`</a> | 对当天的 YYYYMMDD 整数值做加减运算。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L307-L320) |

## N {#n}

| 对象签名 | 用途 | 源码定义 |
|---|---|---|
| <a id="mysql-numeric-timestamp-numeric-25a3c7da" href="#mysql-numeric-timestamp-numeric-25a3c7da">`mysql.numeric_timestamp(numeric) → timestamp without time zone`</a> | 整理日期时间输入，供后续转换为 timestamp without time zone。 | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1503-L1537) |

## r4 中的函数名 {#r4-names}

| 安装快照 (`0d51adc`) | [r4 源码 (`1e631f9`)](https://github.com/pgsty/pg_mysql/blob/1e631f9802c5ae449d6ca93d5326dc5e2e0418df/sql/baseline/44-func-time.sql) |
|---|---|
| `mysql._convert_format_to_halo_for_number_datetime` | `mysql._normalize_numeric_datetime` |
| `mysql._convert_format_to_halo_for_string_datetime` | `mysql._normalize_datetime_text` |
| `mysql._convert_format_to_halo_for_string_number_datetime` | `mysql._normalize_compact_datetime_text` |
| `mysql._convert_format_to_halo_for_string_string_datetime` | `mysql._normalize_delimited_datetime_text` |

---

反链：

- [函数](/zh/docs/mysql/reference/objects/functions/)
