在PostgreSQL中将日期转换为整数

编程入门 行业动态 更新时间:2024-10-23 13:36:44
本文介绍了在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中将日期转换为整数

本文发布于:2023-10-16 12:09:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497510.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   转换为   中将   日期   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!