I am using the PostgreSQL function date_part() to calculate the (inclusive) number of days passed between two dates.
select date_part('day', '2019-12-31 00:00:00'::timestamp
- '2019-01-01 00:00:00'::timestamp);
Running this query in DBeaver returns 1 day less than expected:
| date_part |
|---|
| 364.0 |
It would be as simple as adding +1 to the result, but then the following sentence would return 1 day, which seems wrong:
select 1 + date_part('day', '2019-01-01 00:00:00'::timestamp
- '2019-01-01 00:00:00'::timestamp);
| ?column? |
|---|
| 1.0 |
Is there a better way to have a trusted solution?