background image
<< TIMESTAMPADD function | JDBC escape syntax for outer joins >>

year function

<< TIMESTAMPADD function | JDBC escape syntax for outer joins >>
Derby Reference Manual
330
Use the
TIMESTAMPDIFF
function to find the difference between two timestamp
values at a specified interval. For example, the function can return the number of
minutes between two specified timestamps.
The
TIMESTAMPDIFF
is a JDBC escaped function and is accessible only by using
the JDBC escape function syntax.
TIMESTAMPDIFF( interval, timestampExpression1, timestampExpression2 )
To perform
TIMESTAMPDIFF
on dates and times, it is necessary to convert the dates
and times to timestamps. Dates are converted to timestamps by putting 00:00:00.0 in
the time-of-day fields. Times are converted to timestamps by putting the current date
in the date fields.
Do not put a datetime column inside a timestamp arithmetic function in WHERE
clauses, because the optimizer will not use any index on the column.
year
Returns the year part of a date value.
year(expression)
The JDBC escape syntax
{fn year(expression)}
is equivalent to the built-in
syntax
YEAR(expression)
. For more information, see
YEAR function
.
Valid intervals for TIMESTAMPADD and TIMESTAMPDIFF
The
TIMESTAMPADD
and
TIMESTAMPDIFF
functions are used to perform arithmetic
with timestamps. These two functions use the following valid intervals for arithmetic
operations:
· SQL_TSI_DAY
· SQL_TSI_FRAC_SECOND
· SQL_TSI_HOUR
· SQL_TSI_MINUTE
· SQL_TSI_MONTH
· SQL_TSI_QUARTER
· SQL_TSI_SECOND
· SQL_TSI_WEEK
· SQL_TSI_YEAR
Examples for the TIMESTAMPADD and TIMESTAMPDIFF escape functions
To return a timestamp value one month later than the current timestamp, use the
following syntax:
{fn TIMESTAMPADD( SQL_TSI_MONTH, 1, CURRENT_TIMESTAMP)}
To return the number of weeks between now and the specified time on January 1, 2008,
use the following syntax:
{fn TIMESTAMPDIFF(SQL_TSI_WEEK, CURRENT_TIMESTAMP,
timestamp('2008-01-01-12.00.00.000000'))}
System function
user
Returns the authorization identifier or name of the current user. If there is no current
user, it returns APP.
user()
The JDBC escape syntax
{fn user()}
is equivalent to the built-in syntax
USER
. For
more information, see
USER function
.