DB2: How to Compare Dates

Let us say you get a chance to write DATE in the WHERE clause. Since your query needs DATE comparison, I am going to share with you how to give DATE in the WHERE clause.


I have given three selected examples. You can refer and use the same logic for comparing the DATEs.

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.

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 posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.