> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/appendixes/datetime-appendix/datetime-input-rules.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# B.1. 日期／時間輸入解讀 \#

### B.1. 日期／時間輸入解讀 [#](#datetime-input-rules) <a href="#datetime-input-rules" id="datetime-input-rules"></a>

日期／時間輸入字串會依照下列程序解碼。

1. 將輸入字串拆分為記號（token），並將每個記號歸類為 字串、時間、時區或數字。
   1. 若數字記號包含冒號（`:`），則為 時間字串。其後所有的數字與冒號都包含在內。
   2. 若數字記號包含連字號（`-`）、斜線 （`/`），或兩個以上的句點（`.`），則為 可能含有文字月份的日期字串。若先前已經出現過日期記號， 則改為將它解讀為時區名稱（例如 `America/New_York`）。
   3. 若記號只由數字組成，則它不是單一欄位， 就是 ISO 8601 的連寫日期（例如 `19990113` 表示 1999 年 1 月 13 日）或連寫時間 （例如 `141516` 表示 14:15:16）。
   4. 若記號以加號（`+`）或減號 （`-`）開頭，則它不是數字時區，就是特殊 欄位。
2. 若記號是英文字母字串，則與可能的字串比對：
   1. 檢查該記號是否符合任何已知的時區縮寫。 這些縮寫由[第 B.4 節](https://docs.postgresql.tw/19/appendixes/datetime-appendix/datetime-config-files.md) 所述的設定決定。
   2. 若找不到，則搜尋內部查詢表， 將該記號比對為特殊字串（例如 `today`）、 星期（例如 `Thursday`）、 月份（例如 `January`）， 或無意義字（例如 `at`、`on`）。
   3. 若仍然找不到，則擲出錯誤。
3. 當記號為數字或數字欄位時：
   1. 若有八位或六位數字， 且先前尚未讀到其他日期欄位，則解讀為 「連寫日期」（例如 `19990118` 或 `990118`）。 其解讀方式為 `YYYYMMDD` 或 `YYMMDD`。
   2. 若記號為三位數字， 且已經讀到年份，則解讀為一年中的第幾天。
   3. 若為四位或六位數字，且已經讀到年份，則 解讀為時間（`HHMM` 或 `HHMMSS`）。
   4. 若為三位以上的數字，且尚未找到任何日期欄位， 則解讀為年份（這會強制其餘日期欄位採用 yy-mm-dd 順序）。
   5. 否則，日期欄位的順序會假定依循 `DateStyle` 設定：mm-dd-yy、dd-mm-yy 或 yy-mm-dd。 若發現月份或日期欄位超出範圍，則擲出錯誤。
4. 若指定了 BC（西元前），則將年份取負值再加一，作為 內部儲存值。（格里曆中沒有西元 0 年， 因此在數值上，西元前 1 年會成為第 0 年。）
5. 若未指定 BC，且年份欄位長度為兩位數， 則將年份調整為四位數。若該欄位小於 70，則 加上 2000，否則加上 1900。

   #### 提示

   格里曆西元 1～99 年可以用帶前置零的 4 位數字輸入 （例如 `0099` 表示西元 99 年）。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/datetime-input-rules.html)（原文版本：18.6；核對日期：2026-10-22）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/appendixes/datetime-appendix/datetime-input-rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
