在 postgresql 中将日期转换为整数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28557770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert date to integer in postgresql
提问by nidazakiy
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
我正在尝试将日期(日期类型)转换为 int。这个 int 应该是自 1900 年 1 月 1 日以来的天数。如何在 postgresql 中获得它?在 excel 中,当我将日期与字符串连接时,我会自动获取此信息。示例:2011/11/01 转换为 int 为 36831
采纳答案by a_horse_with_no_name
Simply subtract the two dates:
简单地减去两个日期:
select date '2011-11-01' - date '1900-01-01'
the result will be the number of days.
结果将是天数。
More details in the manual:
http://www.postgresql.org/docs/current/static/functions-datetime.html
手册中的更多详细信息:http:
//www.postgresql.org/docs/current/static/functions-datetime.html