• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8131
  • Last Modified:

PostGreSQL Get difference between two Timestamp in minutes

Hi sir,
I would be thankful to you if you could provide me the SQL query (PostgreSQL specific) to get differnce between two Timestamp in minutes. Its urgent.
0
ekartha
Asked:
ekartha
  • 2
1 Solution
 
ldbkuttyCommented:
0
 
ldbkuttyCommented:
Ok..here is an exact solution:

SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-09-29 13:00' - TIMESTAMP '2001-09-29 12:00')/60;
0
 
earth man2Commented:
he's right you may want to cast it as int if you want to round down minutes.

demo=> select extract ( epoch from (interval '349 second'))/60;
     ?column?
------------------
 5.81666666666667
(1 row)

demo=> select extract ( epoch from (interval '349 second'))::int/60;
 ?column?
----------
        5
(1 row)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now