If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2, editing Timestamp(char) to (string)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-09, 06:35
Yetunde Yetunde is offline
Registered User
 
Join Date: Nov 2009
Posts: 2
Post DB2, editing Timestamp(char) to (integer)

Hi,


I am currently working with DB2 9.1, but my timestamps is in char after running my query, this makes it difficult to interpret this report and I try editing the coloum which I found difficult as well.

I am working on Window server 2003 EE, and I am trying to generate report for ITM using BIRT Bussiness Intelligent reporting tools v2.2.2, my database connection with BIRT was successful but the date of the report is an issue to explain.

Please help me.

Thank u.

Last edited by Yetunde; 11-05-09 at 06:48.
Reply With Quote
  #2 (permalink)  
Old 11-05-09, 07:15
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
try to remove the characters (: . )with translate and convert to integer
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 11-13-09, 11:15
Yetunde Yetunde is offline
Registered User
 
Join Date: Nov 2009
Posts: 2
I have tried all possible best to remove the character to integer but it seems not working, It gives no room for edition.
Reply With Quote
  #4 (permalink)  
Old 11-13-09, 11:27
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
first that comes to mind is:

c1 with value let's say '2002-12-25-17.12.30.123456'

integer(substr(c1,1,4)||substr(c1,6,2)||substr(c1, 9,2)||substr(c1,12,2)... )
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS

Last edited by MarkhamDBA; 11-13-09 at 11:31.
Reply With Quote
  #5 (permalink)  
Old 11-13-09, 11:51
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Arrow Decimal(18,0)

Quote:
Originally Posted by MarkhamDBA View Post
first that comes to mind is:

c1 with value let's say '2002-12-25-17.12.30.123456'

integer(substr(c1,1,4)||substr(c1,6,2)||substr(c1, 9,2)||substr(c1,12,2)... )
Integers have a limit +2147483647.... After this you will get arithmetic exception error.

Better, instead of integer, using DECIMAL(18,0)....

Lenny
Reply With Quote
  #6 (permalink)  
Old 11-13-09, 12:05
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Yetunde,
what format do you want from timestamp 'yyyy-mm-dd-hh.mi.ss.ssssss'?
Reply With Quote
  #7 (permalink)  
Old 11-13-09, 12:22
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
Quote:
Originally Posted by Lenny77 View Post
Integers have a limit +2147483647.... After this you will get arithmetic exception error.

Better, instead of integer, using DECIMAL(18,0)....

Lenny
you are right. actually DECIMAL function can be used to convert timestamp to decimal data type. Excerpt from DB2 SQL documentation:

function with arguments = DECIMAL(2000-03-21-12.02.21.123456, 23)
precision and scale = (23, 6)
result = 20000321120221.123456
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #8 (permalink)  
Old 11-13-09, 12:34
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Post decimal(..., 23) ...instruction to use...

Quote:
Originally Posted by MarkhamDBA View Post
you are right. actually DECIMAL function can be used to convert timestamp to decimal data type. Excerpt from DB2 SQL documentation:

function with arguments = DECIMAL(2000-03-21-12.02.21.123456, 23)
precision and scale = (23, 6)
result = 20000321120221.123456
Actually:

Code:
select decimal(replace(
         translate(varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Lenny
Reply With Quote
  #9 (permalink)  
Old 11-13-09, 13:30
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
Quote:
Originally Posted by Lenny77 View Post
Actually:

Code:
select decimal(replace(
         translate(varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Lenny
Lenny, why do you need replace/translate/varchar here? argument of DECIMAL function can be of timestamp type. I tested it and it works
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS

Last edited by MarkhamDBA; 11-13-09 at 13:39.
Reply With Quote
  #10 (permalink)  
Old 11-13-09, 14:24
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Arrow Like integer

Quote:
Originally Posted by MarkhamDBA View Post
Lenny, why do you need replace/translate/varchar here? argument of DECIMAL function can be of timestamp type. I tested it and it works
Because I don't want to have a fraction....

Code:
select current timestamp, 
decimal(replace(translate(
           varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Now you can operate with result in same way how you are working with integers....

Code:
select 
decimal(replace(translate(
           varchar(current timestamp), ' ', '-.'), ' ', ''), 23)
-
decimal(replace(translate(
            varchar(current timestamp - 111 minute), ' ', '-.'), ' ', ''), 23)
from sysibm.sysdummy1
Lenny
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On