1select EXTRACT(
2 EPOCH FROM now() - (now() - INTERVAL '5 HOUR')
3)/3600
4
5-- it will return 5
1select age('2010-04-01', '2012-03-05'),
2 date_part('year',age('2010-04-01', '2012-03-05')),
3 date_part('month',age('2010-04-01', '2012-03-05')),
4 date_part('day',age('2010-04-01', '2012-03-05'));
1 -- Difference between Dec 30, 2011 08:54:55 and Dec 30, 2011 08:56:10 in minutes
2 SELECT (DATE_PART('day', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp) * 24 * 60 +
3 DATE_PART('hour', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp)) * 60 +
4 DATE_PART('minute', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp);
5 -- Result: 1
6
7 -- Time only
8 SELECT DATE_PART('hour', '08:56:10'::time - '08:54:55'::time) * 60 +
9 DATE_PART('minute', '08:56:10'::time - '08:54:55'::time);
10 -- Result: 1