在PostgreSQL中格式化日期 [英] Formatting dates in PostgreSQL

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

问题描述

我有一个字段,其格式为日期和时间,例如: YYYY-MM-DD HH-MM-SS 例如: 2000- 08-12 00:00:00 我只想获取日期部分并将其格式更改为 DD / MMM / YYYY 上一个示例的结果将是: 12 / Aug / 2000

I have a field which its format is date with time as: YYYY-MM-DD HH-MM-SS for example: 2000-08-12 00:00:00 I want to get just the date part and change its format to DD/MMM/YYYY for example the expected result of the previous example will be: 12/Aug/2000

字段定义为:不带时区的Date时间戳记DEFAULT now()

我阅读了日期/时间函数和运算符以及其他来源,但我找不到任何有用的信息。

I read the whole page of Date/Time Functions and Operators and other sources as well but I couldn't find any information that is helpful.

推荐答案

您可以使用 to_char 函数设置列格式:

You can use the to_char function to format your column:

SELECT TO_CHAR(ddatte, 'dd/Mon/yyyy') FROM mytable

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

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