Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

How calculate date/time difference in DB2

 
   Database Help (Home) -> DB2 RSS
Next:  Filter Factors when using Parameter markers?  
Author Message
lenygold via DBMonster.co

External


Since: Feb 19, 2008
Posts: 80



(Msg. 1) Posted: Tue Sep 02, 2008 1:10 pm
Post subject: How calculate date/time difference in DB2
Archived from groups: comp>databases>ibm-db2 (more info?)

I found this example in MYSQL:
create table events
( id integer not null primary key
, datetime_start datetime not null
, datetime_end datetime not null
);
insert into events values
( 1, '2006-09-09 14:00', '2006-09-09 16:00' )
,( 2, '2006-09-10 09:00', '2006-09-10 17:00' )
,( 3, '2006-09-11 13:30', '2006-09-11 14:45' )
,( 4, '2006-09-12 09:00', '2006-09-15 17:00' );

select id
, datetime_start
, datetime_end
, datetime_end - datetime_start as diff
from events
id datetime_start datetime_end diff
1 2006-09-09 14:00 2006-09-09 16:00 20000
2 2006-09-10 09:00 2006-09-10 17:00 80000
3 2006-09-11 13:30 2006-09-11 14:45 11500
4 2006-09-12 09:00 2006-09-15 17:00 3080000

Can we get in DB2 date/time difference in one query?
Or we have calculate it separate?
Thank's in advance Leny G.

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/ibm-db2/200809/1

 >> Stay informed about: How calculate date/time difference in DB2 
Back to top
Login to vote
Mark A

External


Since: Aug 29, 2008
Posts: 32



(Msg. 2) Posted: Tue Sep 02, 2008 1:10 pm
Post subject: Re: How calculate date/time difference in DB2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"lenygold via DBMonster.com" <u41482@uwe> wrote in message
news:8997776c4097f@uwe...
>I found this example in MYSQL:
> create table events
> ( id integer not null primary key
> , datetime_start datetime not null
> , datetime_end datetime not null
> );
> insert into events values
> ( 1, '2006-09-09 14:00', '2006-09-09 16:00' )
> ,( 2, '2006-09-10 09:00', '2006-09-10 17:00' )
> ,( 3, '2006-09-11 13:30', '2006-09-11 14:45' )
> ,( 4, '2006-09-12 09:00', '2006-09-15 17:00' );
>
> select id
> , datetime_start
> , datetime_end
> , datetime_end - datetime_start as diff
> from events
> id datetime_start datetime_end diff
> 1 2006-09-09 14:00 2006-09-09 16:00 20000
> 2 2006-09-10 09:00 2006-09-10 17:00 80000
> 3 2006-09-11 13:30 2006-09-11 14:45 11500
> 4 2006-09-12 09:00 2006-09-15 17:00 3080000
>
> Can we get in DB2 date/time difference in one query?
> Or we have calculate it separate?
> Thank's in advance Leny G.

Try the SQL Reference manual Vol 1
http://www-01.ibm.com/support/docview.wss?rs=71&uid=swg27009727

 >> Stay informed about: How calculate date/time difference in DB2 
Back to top
Login to vote
Tonkuma

External


Since: Jan 30, 2008
Posts: 62



(Msg. 3) Posted: Tue Sep 02, 2008 1:10 pm
Post subject: Re: How calculate date/time difference in DB2 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

you can use TIMESTAMPDIFF function.
But, I think that it is not accurate, it is estimation.

Please see here for basic handlings of date/time data types on DB2.
Fun with Dates and Times
http://www.ibm.com/developerworks/db2/library/techarticle/0211yip/0211yip3.html

You may be able to use the folowing expression for exsact difference
of timestamp.
DAYS(datetime_end )*24*60*60 + MICROSECONDS(datetime_end )
-
DAYS(datetime_start)*24*60*60 + MICROSECONDS(datetime_start)
 >> Stay informed about: How calculate date/time difference in DB2 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> DB2 All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]