# Temporal conversion helpers

> Internal routines for date normalization, week modes and numeric date arithmetic.

---

LLMS index: [llms.txt](/llms.txt)

---

Internal routines for date normalization, week modes and numeric date arithmetic.

## _ {#underscore}

| Signature | Purpose | Source definition |
|---|---|---|
| <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> | Count days in the given year. | [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> | Calculate the weekday or week number under MySQL week rules. | [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> | Calculate the weekday or week number under MySQL week rules. | [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> | Normalize date/time input for conversion to 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> | Normalize date/time input for conversion to 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> | Normalize date/time input for conversion to 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> | Normalize date/time input for conversion to 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> | Normalize date/time input for conversion to 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> | Normalize date/time input for conversion to 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> | Normalize date/time input for conversion to 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> | Calculate the weekday or week number under MySQL week rules. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L931-L944) |

## C {#c}

| Signature | Purpose | Source definition |
|---|---|---|
| <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> | Normalize date/time input for conversion to 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> | Apply integer arithmetic to today’s YYYYMMDD value. | [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> | Apply integer arithmetic to today’s YYYYMMDD value. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L307-L320) |

## N {#n}

| Signature | Purpose | Source definition |
|---|---|---|
| <a id="mysql-numeric-timestamp-numeric-25a3c7da" href="#mysql-numeric-timestamp-numeric-25a3c7da">`mysql.numeric_timestamp(numeric) → timestamp without time zone`</a> | Normalize date/time input for conversion to timestamp without time zone. | [SQL](https://github.com/pgsty/pg_mysql/blob/0d51adcf5151ca5c98bc61de84f287ec3b4fe4a3/sql/baseline/44-func-time.sql#L1503-L1537) |

## Function names in r4 {#r4-names}

| Installation snapshot (`0d51adc`) | [r4 source (`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` |

---

Backlinks:

- [Functions](/docs/mysql/reference/objects/functions/)
