Comparing DB2 dates

db2
yons88 picture yons88 · May 28, 2012 · Viewed 88.4k times · Source

I have a DB2 DATE type field in a DB2 table. I want to select data by a date filter. For example:

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

From the above query, I get records with registrationdate starting from '1943-10-01', but this is incorrect.

These do not work either:

registrationdate > date('2002-10-01')
date(registrationdate) > date('2002-10-01')
date(registrationdate) > '2002-10-01'

How do I need to compare dates?

Answer

Jonathan Leffler picture Jonathan Leffler · May 28, 2012

The SQL standard format for a DATE literal is:

DATE '2002-10-01'

At the very least, it is worth trying:

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