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 > Conversion of integer to timestamp format

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-09, 12:35
db2user db2user is offline
Registered User
 
Join Date: Dec 2002
Posts: 123
Conversion of integer to timestamp format

Hi,

How can I convert an integer to db2 timestamp format? For example, I have the number 1240341010 and would like to convert it to a format like 2009-10-10-05.00.00.000000

Thanks!!
Reply With Quote
  #2 (permalink)  
Old 10-15-09, 13:02
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Wink

select timestamp(date(1240), time('3:41')) + 010 microsecond
from sysibm.sysdummy1

Lenny
Reply With Quote
  #3 (permalink)  
Old 10-15-09, 13:08
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
The internal representation of a timestamp is a string of 10 bytes.
Each byte consists of 2 packed decimal digits.
The first 4 bytes represent the date, the next 3 bytes the time, and the last 3 bytes the microseconds.

Lenny
Reply With Quote
  #4 (permalink)  
Old 10-15-09, 13:11
db2user db2user is offline
Registered User
 
Join Date: Dec 2002
Posts: 123
thanks for the response -- this is what I get back :

db2 "select timestamp(date(1240), time('3:41')) + 010 microsecond from sysibm.sysdummy1"

1
--------------------------
0004-05-24-03.41.00.000010


It should give -- 2009-04-21-19.10.10
I forgot to mention that the integer is the number of seconds since Jan 1, 1970... in any case, I appreciate the response!

Last edited by db2user; 10-15-09 at 13:14.
Reply With Quote
  #5 (permalink)  
Old 10-15-09, 13:34
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
you storing timestamp in integer field?
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #6 (permalink)  
Old 10-15-09, 13:48
db2user db2user is offline
Registered User
 
Join Date: Dec 2002
Posts: 123
Someone i used to work with wrote a program that inserts time into a table in integer format.. bad idea I know!
Reply With Quote
  #7 (permalink)  
Old 10-15-09, 15:47
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Thumbs up

Quote:
Originally Posted by db2user
thanks for the response -- this is what I get back :

db2 "select timestamp(date(1240), time('3:41')) + 010 microsecond from sysibm.sysdummy1"

1
--------------------------
0004-05-24-03.41.00.000010


It should give -- 2009-04-21-19.10.10
I forgot to mention that the integer is the number of seconds since Jan 1, 1970... in any case, I appreciate the response!
Code:
select timestamp(date('1970-01-01'), time('00:00:00')) + 1240341010 second NTMS
from sysibm.sysdummy1
Quote:
NTMS
2009-04-21 19:10:10.000000
It's Funny

Lenny Kh.
Reply With Quote
  #8 (permalink)  
Old 10-15-09, 16:29
db2user db2user is offline
Registered User
 
Join Date: Dec 2002
Posts: 123
great, thank you!!
Reply With Quote
  #9 (permalink)  
Old 10-15-09, 16:33
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Quote:
Originally Posted by db2user
great, thank you!!
No problem !
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