Skip to content

Instantly share code, notes, and snippets.

@younisshah
Last active March 18, 2022 05:35
Show Gist options
  • Save younisshah/633cd4cca00d8bac4e966eebe6f9fad8 to your computer and use it in GitHub Desktop.
Save younisshah/633cd4cca00d8bac4e966eebe6f9fad8 to your computer and use it in GitHub Desktop.
[PostgreSQL] Difference between two timestamps in minutes

In PostgreSQL, difference between two timestamps in minutes can be calculated by providing the EPOCH as a sub-field to the EXTRACT function, and the result from the EXTRACT will be divided by 60 to get the minutes.

Example

SELECT EXTRACT(EPOCH FROM ((NOW() + interval '1 day')::TIMESTAMPZ - NOW())) / 60 AS minutes
SELECT EXTRACT(EPOCH FROM (end_date - start_date)) / 60 AS minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment