加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 如何更改Postgres中的日期格式?

发布时间:2020-12-13 16:41:24 所属栏目:百科 来源:网络整理
导读:我收到以下错误消息 错误:日期/时间字段值超出范围:“13/01/2010” 提示:也许你需要一个不同的“数据式”设置。 我想以DD / MM / YYYY格式获取日期 SHOW datestyle; DateStyle ----------- ISO,MDY(1 row)INSERT INTO container VALUES ('13/01/2010');ER
我收到以下错误消息

错误:日期/时间字段值超出范围:“13/01/2010”
提示:也许你需要一个不同的“数据式”设置。

我想以DD / MM / YYYY格式获取日期

SHOW datestyle;

 DateStyle 
-----------
 ISO,MDY
(1 row)

INSERT INTO container VALUES ('13/01/2010');
ERROR:  date/time field value out of range: "13/01/2010"
HINT:  Perhaps you need a different "datestyle" setting.

SET datestyle = "ISO,DMY";
SET

INSERT INTO container VALUES ('13/01/2010');
INSERT 0 1

SET datestyle = default;
SET

http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DATESTYLE

DateStyle – Sets the display format
for date and time values,as well as
the rules for interpreting ambiguous
date input values.
For historical reasons,this variable
contains two independent components:
the output format specification (ISO,
Postgres,SQL,or German) and the
input/output specification for
year/month/day ordering (DMY,MDY,or
YMD).

当然最好使用明确的输入格式(ISO 8601),但根据需要进行调整是没有问题的。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读