Answers for "postgres date difference in days"

SQL
1

postgresql difference between two dates in days

SELECT
  AGE('2012-03-05', '2010-04-01'),
  DATE_PART('year', AGE('2012-03-05', '2010-04-01')) AS years,
  DATE_PART('month', AGE('2012-03-05', '2010-04-01')) AS months,
  DATE_PART('day', AGE('2012-03-05', '2010-04-01')) AS days;
 
...  
-- This will give you full years, month, days ... between two dates:

--          age          | years | months | days
-- -----------------------+-------+--------+------
--  1 year 11 mons 4 days |     1 |     11 |    4
Posted by: Guest on March-11-2021
1

postgres date difference seconds

-- difference in seconds between two dates

select extract(epoch from ('2020-03-30 09:55:56'::timestamp - '2020-03-30 08:54:55'::timestamp));
-- result : 3661
Posted by: Guest on October-14-2020
-1

postgresql get difference between two dates

select age('2010-04-01', '2012-03-05'),
       date_part('year',age('2010-04-01', '2012-03-05')),
       date_part('month',age('2010-04-01', '2012-03-05')),
       date_part('day',age('2010-04-01', '2012-03-05'));
Posted by: Guest on April-08-2020
0

DATEDIFF minute postgres

-- Difference between Dec 30, 2011 08:54:55 and  Dec 30, 2011 08:56:10 in minutes
  SELECT (DATE_PART('day', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp) * 24 * 60 + 
               DATE_PART('hour', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp)) * 60 +
               DATE_PART('minute', '2011-12-30 08:56:10'::timestamp - '2011-12-30 08:54:55'::timestamp);
  -- Result: 1
 
  -- Time only
  SELECT DATE_PART('hour', '08:56:10'::time - '08:54:55'::time) * 60 +
              DATE_PART('minute', '08:56:10'::time - '08:54:55'::time);
  -- Result: 1
Posted by: Guest on February-25-2020

Code answers related to "postgres date difference in days"

Code answers related to "SQL"

Browse Popular Code Answers by Language