Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Postgresql how to query a time duration?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"

>Solution :

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

select * 
from case 
where check_out - check_in > interval '2 days';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading