PostgreSQL:整数至今 [英] Postgresql: Integer to Date

查看:63
本文介绍了PostgreSQL:整数至今的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将整数日期(20180525)转换为YYYY-MM-DD格式的日期时遇到问题。有没有办法做到这一点,还是我应该将其转换为代码(在这种情况下为Java)?任何帮助,将不胜感激。谢谢!

I am having an issue with converting an integer date (20180525) to a date in the format of YYYY-MM-DD. Is there a way to do this or should I just convert it in code (Java in this case)? Any help with this would be most appreciated. Thank you!

推荐答案

如果您的日期使用YYYYMMDD存储为整数,则可以通过先将其转换为date函数将其传递给date函数。 TEXT

if your dates are stored as integers with YYYYMMDD, you can pass it to the date function by first casting to TEXT.

SELECT date(20180525::TEXT)

否则,将函数to_date与日期格式化程序一起使用:

otherwise, use the function to_date with a date formatter:

SELECT to_date(20180525::text, 'YYYYMMDD')

这篇关于PostgreSQL:整数至今的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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