Date subtraction SQL snippet for OpenOffice base
Posted in Programming by Julian Kessel - Oct 23, 2009
With this simple line condition in OpenOffice base’s hsqldb it is possible to subtract a date fragment, and in order to this, select the matching entries. My example is a query on a column containing birthdates in the german format DD-MM-YY.
It selects the entries (persons) who are under the age of 20.
SELECT “birthdate” AS “Birthdate” FROM “under20″ AS “under20″ WHERE (datediff(‘yy’, “BIRTHDATE”, CURRENT_DATE)) <= 20
Instead of ‘yy’ it’s possible to take the following other values:
‘ms’=millisecond
‘ss’=second
‘mi’=minute
‘hh’=hour
‘dd’=day
‘mm’=month
COMMENTS
