EN
PostgreSQL - compare date values
0 points
In this article, we would like to show you how to compare date values in PostgreSQL.
Quick solution:
xxxxxxxxxx
1
SELECT *
2
FROM "table_name"
3
WHERE "date_column_name" <= 'yyyy-mm-dd';
Note:
You can replace the
<=
operator with any other comparison operator.
To show how to compare date values, we will use the following table:

Note:
At the end of this article you can find database preparation SQL queries.
In this example, we will display all the dates before 2000-01-04
.
Query:
xxxxxxxxxx
1
SELECT *
2
FROM "dates"
3
WHERE "date" < '2000-01-04';
Output:

In this example, we will select all the rows from 2000-01-04
inclusive and display them without time using DATE()
function (yyyy-mm-dd
format only).
Query:
xxxxxxxxxx
1
SELECT "date"
2
FROM "dates"
3
WHERE "date" <= '2000-01-04';
Output:

create_tables.sql
file:
xxxxxxxxxx
1
create TABLE "dates"(
2
"id" SERIAL PRIMARY KEY,
3
"date" DATE
4
);
insert_data.sql
file:
xxxxxxxxxx
1
insert into "dates"
2
("date")
3
VALUES
4
('2000-01-01'),
5
('2000-01-02'),
6
('2000-01-03'),
7
('2000-01-04'),
8
('2000-01-05'),
9
('2000-01-06');