本文介绍了在PostgreSQL中将日期转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将日期(日期类型)转换为整数。此int应该类似于自1900年1月1日以来的天数。如何在postgresql中获得它?在excel中,当我用字符串连接日期时,会自动获得此信息。 示例:2011/11/01转换为int为36831
I'm trying to convert a date (date type) into int. This int should be something like the number of days since the 1 January 1900. How to get this in postgresql? In excel I'm getting this automatically when i concatenate a date with a string. Example : 2011/11/01 convert into int as 36831
推荐答案简单地减去两个日期:
select date '2011-11-01' - date '1900-01-01'结果将是天数。
手册中的更多详细信息: www.postgresql/docs/ current / static / functions-datetime.html
More details in the manual: www.postgresql/docs/current/static/functions-datetime.html
更多推荐
在PostgreSQL中将日期转换为整数
发布评论