简体   繁体   English

如何获得日期间隔从postgres的天数

[英]how to obtain interval from date on postgres in days

I have two columns, say "2010-10-26" and "2010-08-23" and I would like to obtain the interval in days, what is the best way to do this on a select query taking into account that there are months with 30,31,29,28 days? 我有两列,分别是“ 2010-10-26”和“ 2010-08-23”,我想获得以天为单位的间隔,考虑到有30,31,29,28天的月份? Is there any function that already does this? 有没有已经执行此功能的功能?

Thank you. 谢谢。

If they are already in the date format, it's very easy: 如果它们已经是日期格式,则非常简单:

SELECT '10/26/2010'::date - '08/23/2010'::date;

OR: 要么:

SELECT date '2001-10-01' - date '2001-09-28'; // outputs integer 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM