Derby 10.1 supports datetime arithmetic... Adding a constant interval to a datetime (timestampadd) or subtracting one datetime with another (timestampdiff). However, these operators are only present as JDBC escape functions, so you need to invoke them using standard JDBC function invocation syntax. ( {fn func()}

Check out the (confusing) syntax in 10.1 reference manual:

ij> select {fn timestampdiff(SQL_TSI_DAY, {d '2000-01-01'}, {d '2000-01-10'})}
as date_diff from oneRow;

1 row selected


Maciej Bliziński wrote:
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;
(1 row)

Similar thing with Derby brings an error message:

ij> SELECT DATE('2000-01-10') - DATE('2000-01-01') AS date_diff FROM
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?