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 Using DATE ‘>’ 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 comparisions.

DB2 DATE Blogs

DB2 Date formats Tutorial unlock now

DB2 date formats complete list read today and useful for your projects.

DB2 Date, Time examples for advanced learners

The best examples on DB2 date and time. You can play with them and use them into your project directly. Many complex DATE and TIME problems explained with detailed solutions. Good for advanced learners.

SQL Query Using DATE ‘<‘ 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.