from Hacker News

PostgreSQL's Missing DateDiff Function

by cedricd on 12/21/21, 9:49 PM with 57 comments

  • by Izkata on 12/21/21, 10:42 PM

    Isn't this what EXTRACT does? (Note the first paragraph that says it works on "interval" types)

    https://www.postgresql.org/docs/9.3/functions-datetime.html#...

    Just did a search and got it from here, which shows it being used on the difference between two dates: https://stackoverflow.com/questions/24929735/how-to-calculat...

  • by jimktrains2 on 12/21/21, 11:47 PM

    > DATEDIFF('year', '12-31-2020', '01-01-2021') returns 1 because even though the two dates are a day apart, they've crossed the year boundary.

    What is the use of such a function? If I saw this answer I would assume a bug somewhere (until reading the documentation).

  • by xupybd on 12/21/21, 10:11 PM

    This seems like a big yet simple feature that Postgresql is missing. I've used this many times in SQL server.

    I'm surprised there is not native function. Does anyone know why?