TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PostgreSQL's Missing DateDiff Function

78 pointsby cedricdover 3 years ago

3 comments

Izkataover 3 years ago
Isn&#x27;t this what EXTRACT does? (Note the first paragraph that says it works on &quot;interval&quot; types)<p><a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;9.3&#x2F;functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;9.3&#x2F;functions-datetime.html#...</a><p>Just did a search and got it from here, which shows it being used on the difference between two dates: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;24929735&#x2F;how-to-calculate-date-difference-in-postgresql" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;24929735&#x2F;how-to-calculat...</a>
评论 #29643047 未加载
评论 #29643034 未加载
评论 #29643077 未加载
jimktrains2over 3 years ago
&gt; DATEDIFF(&#x27;year&#x27;, &#x27;12-31-2020&#x27;, &#x27;01-01-2021&#x27;) returns 1 because even though the two dates are a day apart, they&#x27;ve crossed the year boundary.<p>What is the use of such a function? If I saw this answer I would assume a bug somewhere (until reading the documentation).
评论 #29644778 未加载
评论 #29646332 未加载
评论 #29643639 未加载
xupybdover 3 years ago
This seems like a big yet simple feature that Postgresql is missing. I&#x27;ve used this many times in SQL server.<p>I&#x27;m surprised there is not native function. Does anyone know why?
评论 #29646321 未加载
评论 #29642812 未加载
评论 #29643784 未加载
评论 #29643321 未加载