Answers for "postgresql difference between dates"

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
2

postgresql get difference in hours between two dates

select EXTRACT(
	EPOCH FROM now() - (now() - INTERVAL '5 HOUR')
)/3600

-- it will return 5
Posted by: Guest on March-04-2021
0

postgres between dates

SELECT user_id 
FROM user_logs 
WHERE login_date BETWEEN '2014-02-01' AND '2014-03-01'
Posted by: Guest on September-03-2021

Code answers related to "postgresql difference between dates"

Code answers related to "SQL"

Browse Popular Code Answers by Language