Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date comparison in PostgreSQL

Is there a way to compare two dates in the same table like this:

SELECT * FROM mytable WHERE date_1 = date_2;

I am looking for the simplest approach to do this as part of an update statement.

like image 651
aeupinhere Avatar asked Nov 27 '25 19:11

aeupinhere


1 Answers

Yes, you can do that. Simple as that.

Have a look at the date / time data types in PostgreSQL.

You may have to pay special attention if your "date", in fact, is a timestamp. By default up to 6 fractional digits are saved, can be tricky with the equality operator. You might cast to timestamp(0) to round to seconds or use date_trunc() to truncate to one of various time units.

like image 105
Erwin Brandstetter Avatar answered Dec 02 '25 09:12

Erwin Brandstetter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!