Home > Net >  Postgresql how to query a time duration?
Postgresql how to query a time duration?

Time:12-14

In my table case ,there are 2 tiemstamp fields looks like:

check_in                check_out
"2021-09-07 07:25:00"   "2021-09-08 17:10:00"
"2020-09-25 06:02:00"   "2020-09-27 15:20:00"
"2020-10-26 05:42:00"   "2020-10-29 13:05:00"

How can I query the rows that check_out - check_in larger than 2 days,something like:

select * from case where check_out - check_in > 2 days ;

Then output will be:

check_in                check_out
"2020-09-25 06:02:00"   "2020-09-27 15:20:00"
"2020-10-26 05:42:00"   "2020-10-29 13:05:00"

CodePudding user response:

You were close. You need to give a correct interval value

select * 
from case 
where check_out - check_in > interval '2 days';
  • Related