era s'q
era s'q

Reputation: 591

How to get exact date difference in days in postgreSQL?

I'm trying to get the difference between the two dates in a number of days in PostgreSQL. But I'm getting the exact value as expected.

For Example, Time at UTC now is 2021-12-30 10:50:00.

If I take a timestamp of more than one day. Let's say, 2021-12-29 09:00:00 which is more than 24hrs from now.

So, If I do select (NOW()::DATE - '2021-12-29 09:00:00'::DATE)<=1; It should give me false. But it's giving me true; But the date difference is more than 24hrs doesn't that make it 2 days? What am I missing?. I also tried : DATE_PART('day', NOW()::timestamp - DATE_OF_RECORDING::timestamp) but same result.

Upvotes: 0

Views: 506

Answers (1)

jarlh
jarlh

Reputation: 44696

(NOW() - timestamp '2021-12-29 09:00:00') < interval'1' day

https://dbfiddle.uk/?rdbms=postgres_14&fiddle=835db28ba753587f5ab552d7537ba3e3

Upvotes: 1

Related Questions