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.
ekarthaAsked:
Who is Participating?
 
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
 
ldbkuttyCommented:
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.

All Courses

From novice to tech pro — start learning today.