Comparing Two Dates
[Deleted User]
Administrator
Jim Knicely authored this post.
There are several cool built-in functions that you can use to compare two dates.
Example:
dbadmin=> SELECT today, dbadmin-> yesterday, dbadmin-> DATE_EQ(today, yesterday) AS date_equal, dbadmin-> DATE_GE(today, yesterday) AS date_greater_than_or_equal, dbadmin-> DATE_GT(today, yesterday) AS date_greater_than, dbadmin-> DATE_LE(today, yesterday) AS date_less_than_or_equal, dbadmin-> DATE_LT(today, yesterday) AS date_less_than dbadmin-> FROM (SELECT sysdate::date AS today, dbadmin(> (sysdate-1)::date AS yesterday) foo; today | yesterday | date_equal | date_greater_than_or_equal | date_greater_than | date_less_than_or_equal | date_less_than ------------+------------+------------+----------------------------+-------------------+-------------------------+---------------- 2018-07-25 | 2018-07-24 | f | t | t | f | f (1 row)
Have fun!
0