在Postgresql中计算日期差 [英] Calculating difference of dates In Postgresql

查看:893
本文介绍了在Postgresql中计算日期差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出表格中某些字段之间的时间。但是,由于我使用的是Postgresql :((,我无法使用DATEDIFF函数。我在网上找不到任何清晰的指南/教程,这些指南/教程显示了如何在Postgres中执行类似的操作,因此我需要做同样的事情,但是在Postgres中需要帮助。

I'm trying to find out the time between certain fields in my tables. However cause I'm using Postgresql :(( I can't use the DATEDIFF function. I can't find any clear guides/ tutorials on the net which shows how to do a similar thing in Postgres so I need help doing the same thing but in Postgres

我假设如果我使用的是支持DATEDIFF函数的RDBMS,则此查询将起作用,所以基本上我的问题是我可以更改它以便使用Postgresql提供的功能吗?

I'm assuming this query would work if I was using a RDBMS that supported the DATEDIFF function so basically my question is how can I change this so it works using features provided by Postgresql?

SELECT Question.ID, 
Question.Status, COUNT (qUpdate.ID)  AS NumberofUpdates,
DATEDIFF (Question.LoggedTime,MIN(qUpdate.UpdateTime)) AS TimeBeforeFirstUpdate,
DATEDIFF(Question.LoggedTime, MAX(qUpdate.UpdateTime)) AS TimeBeforeLastUpdate
FROM qUpdate
LEFT JOIN Question ON qUpdate.qID=Question.ID
WHERE Question.Status = 'closed' AND qUpdate.Update NOT NULL
GROUP BY Question.Status, Question.ID, Question.LoggedTime;

如果您需要更多信息或澄清,我将尽快答复。

If you need more info or any clarification I'll responsd ASAP.

推荐答案

您不需要 datediff功能。

You don't need a "datediff" function.

只需减去两个日期:

Question.LoggedTime - MIN(qUpdate.UpdateTime)

如果您不知道,但在线记录的全部内容:

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

In case you don't know, but all that is documented online:
http://www.postgresql.org/docs/current/static/functions-datetime.html

这篇关于在Postgresql中计算日期差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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