You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Maciej Bliziński <ma...@magnum2.pl> on 2005/08/07 09:20:24 UTC

How to get a difference between two dates?

Hello everybody,

I have a question about getting a date difference in Derby. I tried
Derby online docs, Google (web and newsgroups) and got no results.

For example, in PostgreSQL I can get a difference of two dates:

SELECT '2000-01-10'::DATE - '2000-01-01'::DATE AS date_diff;
 date_diff
-----------
         9
(1 row)

Similar thing with Derby brings an error message:

ij> SELECT DATE('2000-01-10') - DATE('2000-01-01') AS date_diff FROM
dict_country;
ERROR 42Y95: The '-' operator with a left operand type of 'DATE' and a
right operand type of 'DATE' is not supported.

("FROM dict_country" was added only because Derby needs a FROM clause,
while PostgreSQL doesn't)

So, if substraction of two dates is not supported, how can I get a
difference in days between two dates? 

-- 
Maciej Bliziński <ma...@magnum2.pl>
Software development, server administration.