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 "el.pregunton" <ol...@gmail.com> on 2010/04/10 06:54:46 UTC

Re: Timestamp Arithmetic

Two questions that the Derby Documentation does not mentions, 

What happens when the 1st timestamp is more recent than the 2nd in the
timestampdiff function? and what is the result when the 2nd timestamp is
more recent than the 1st?

thanks

Rajesh Kartha-2 wrote:
> 
> Jose de Castro wrote:
> 
>> I trying to calculate the duration (in seconds) between two 
>> timestamps. Historically, I have either used a non-standard function 
>> such as DateDiff in SQL Server and MySQL or performed a direct 
>> arithmetic calculation (i.e. timestamp1-timestamp2) in PostgreSQL.
>>
>> I have searched the reference documentation and tried both of the 
>> aforementioned solutions with no success. I am running the latest 
>> stable Derby build (10.2) on  a Windows XP box.
>>
>> What is the correct way of doing this in Derby?
>>
>>
>> Thanks in advance,
>>
>> Jose de Castro
>> Senior Software Engineer
>> Voxeo Corporation
>> jose.decastro@voxeo.com
>>
>>
> 
> Derby has TIMESTAMPDIFF and TIMESTAMPADD functions and is there in the 
> Reference manual at:
> http://db.apache.org/derby/docs/10.2/ref/rrefjdbc88908.html
> 
> ij> create  table atab1(ts timestamp, i int, ts1 timestamp);
> ij> insert into atab1 values(CURRENT_TIMESTAMP, 1, CURRENT_TIMESTAMP);
> 1 row inserted/updated/deleted
> ij> insert into atab1 values(CURRENT_TIMESTAMP, 2, CURRENT_TIMESTAMP);
> 1 row inserted/updated/deleted
> ij> select {fn TIMESTAMPDIFF(SQL_TSI_SECOND, ts1,ts)} as TS_DIFF from
> atab1;
> TS_DIFF
> -----------
> 0
> 0
> 
> 2 rows selected
> 
> HTH,
> -Rajesh
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Timestamp-Arithmetic-tp7342697p28199979.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.