如何更改Postgres中的日期格式? [英] How do I alter the date format in Postgres?

查看:386
本文介绍了如何更改Postgres中的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误消息

错误:日期/时间字段值超出范围: 13/01/2010
提示:也许您需要其他日期样式设置。

ERROR: date/time field value out of range: "13/01/2010" HINT: Perhaps you need a different "datestyle" setting.

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

I want to get my date in the format 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-设置日期和时间值的显示格式
,以及
解释模糊$的规则b $ b日期输入值。
出于历史原因,此变量
包含两个独立的组件:
输出格式规范(ISO,
Postgres,SQL或德语)和
输入/输出
年/月/日订购的规格(DMY,MDY或
YMD)。

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),但是根据需要进行调整没有问题。

Of course it's best to use unambiguous input format (ISO 8601), but there is no problem to adjust it as you need.

这篇关于如何更改Postgres中的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆