How to Compare Dates in DB2: SQL Query You Need

Here’s the brilliant idea of comparing Dates in SQL. The query is helpful for DB2 SQL developers. For this demo, I chose three examples. This logic you can follow for comparing the DATEs in your project.

SQL Query Compares Dates using ‘>’ Greater than

SELECT *
FROM   table
WHERE purchdate > '2002-10-01';

The syntax for DATE is

datecolumn > ‘XXXX-XX-XX’

  • Always you need to give date in quotes.
  • You can use <, >, = in DATE comparisons.
Advertisements

SQL Query Compare Dates using ‘<‘ Less than

SELECT *
FROM table
WHERE purchdate < '2002-10-10';

SQL Query Using DATE ‘=’ Equal to

SELECT *
FROM table
WHERE purchdate = '2020-04-19;

Related

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading