在PostgreSQL中将日期转换为整数 [英] convert date to integer in postgresql

查看:1964
本文介绍了在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'

结果将是天数。

手册中的更多详细信息:

http://www.postgresql.org/docs/ current / static / functions-datetime.html

More details in the manual:
http://www.postgresql.org/docs/current/static/functions-datetime.html

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

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