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 with Dates

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-09, 12:00
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
Conversion with Dates

According to a quick google, the JMSTimestamp is:
The value is in the format of a normal millis absolute time value in the Java programming language, which is the difference, measured in milliseconds, between the a given time and midnight, January 1, 1970 UTC.

SET @MiliSeconds = 1241091011533
SELECT DATEADD(MS, @MiliSeconds % 1000, DATEADD(SECOND, @MiliSeconds / 1000, '19700101'))

How to use this in DB2 above command is for Microsoft SQL Server only.
Reply With Quote
  #2 (permalink)  
Old 05-04-09, 12:43
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
select ms + (miliseconds * 1000) MICROSECONDS

Andy
Reply With Quote
  #3 (permalink)  
Old 05-04-09, 13:13
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
How to do this in DB2

String s = "1241436617660";
java.sql.Date sqlDate = new java.sql.Date(Long.parseLong(s.trim()));

System.out.println("utilDate:" + utilDate);
System.out.println("sqlDate:" + sqlDate);

Result -
utilDate:Mon May 04 13:04:38 EDT 2009
sqlDate:2009-05-04

I want to give input as string "1241436617660" in DB2 and get result as "Mon May 04 13:04:38EDT 2009". Which query can give such results.
Reply With Quote
  #4 (permalink)  
Old 05-04-09, 14:53
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You want to use java.sql.Timestamp, not java.sql.Date.

Andy
Reply With Quote
  #5 (permalink)  
Old 05-04-09, 15:27
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
This is not giving Time correctly, how do we use this

select
DATE(
TIMESTAMP('1970-01-01','00.00.00')
+ (1241436617660 <from table>/1000) seconds ) , TIME(
TIMESTAMP('1970-01-01','00.00.00')
+ (<from table>/1000) seconds ) from <table_name>
Reply With Quote
  #6 (permalink)  
Old 05-04-09, 15:57
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What is the data type of the column you are using?

And, what is the result you are getting?

Andy
Reply With Quote
  #7 (permalink)  
Old 05-04-09, 16:10
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
Datatype is xml type, have used Xquery to fetch from the XML
timestampis varchar(2000) and then casted to decimal CAST(t.timestampis as DECIMAL(31,0)

--QYERY IS ---

select t.destination, t.message_id,v.ts, DATE(
TIMESTAMP('1970-01-01','00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) , TIME(
TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds )
,t.timestampis,t.bodyis
from table_UNDELIVERED v,
xmltable( 'declare namespace jms1="http://www.abc.com/namespaces/tnt/plugins/jms"; $c/jms1:ActivityOutput' passing v.message as "c"
columns
destination varchar(200) path 'declare namespace jms1="http://www.abc.com/namespaces/tnt/plugins/jms";JMSHeaders/jms1:JMSDestination' ,
message_id varchar(200) path 'declare namespace jms1="http://www.abc.com/namespaces/tnt/plugins/jms"; JMSHeaders/jms1:JMSMessageID',
timestampis varchar(200) path 'declare namespace jms1="http://www.abc.com/namespaces/tnt/plugins/jms"; JMSHeaders/jms1:JMSTimestamp',
bodyis varchar(2000) path 'declare namespace jms1="http://www.abc.com/namespaces/tnt/plugins/jms"; Body'
) as t
where (v.ts < current timestamp ) and (v.ts + 24 hours> current timestamp )

RESULT SHOULD show 5th column - TIME as 07:30:47 AM but its showing as 11:30:17 ,looks to me as

TIME(
TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds )

is not correct
Reply With Quote
  #8 (permalink)  
Old 05-04-09, 16:20
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Add these columns to your query and see if they are correct:

TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds )


CAST(t.timestampis as DECIMAL(31,0))/1000

Andy
Reply With Quote
  #9 (permalink)  
Old 05-04-09, 17:13
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
Hi Andy,

These cloumns alrerady exist ....

select
DATE(
TIMESTAMP('1970-01-01','00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) , TIME( TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds )
from <table name>

Result for second column (TIME) is not correct, its giving different values...
Reply With Quote
  #10 (permalink)  
Old 05-04-09, 17:21
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I think you misunderstood me. Change this query:


select
DATE(
TIMESTAMP('1970-01-01','00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) , TIME( TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds )
from <table name>

to this:


select
DATE(
TIMESTAMP('1970-01-01','00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) , TIME( TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),
TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),
TIMESTAMP('1970-01-01-00.00.00')
CAST(t.timestampis as DECIMAL(31,0))/1000
from <table name>

Then see if the value look OK for the ne columns.


Andy
Reply With Quote
  #11 (permalink)  
Old 05-04-09, 17:27
funnyme.25 funnyme.25 is offline
Registered User
 
Join Date: May 2009
Posts: 11
Can you confirm, query has some problem.. what are 3rd and 4th select doing...

select

DATE(TIMESTAMP('1970-01-01','00.00.00') + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) ,

TIME( TIMESTAMP('1970-01-01-00.00.00') + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),

TIMESTAMP('1970-01-01-00.00.00') + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),

TIMESTAMP('1970-01-01-00.00.00')
CAST(t.timestampis as DECIMAL(31,0))/1000

from <table name>


This doesnot work...
Reply With Quote
  #12 (permalink)  
Old 05-05-09, 05:11
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
This doesnot work...
What means that?
Did you got error message(s)?
Or, did you got wrong(different from your expectations) results?
Reply With Quote
  #13 (permalink)  
Old 05-05-09, 08:38
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by funnyme.25
Can you confirm, query has some problem.. what are 3rd and 4th select doing...

select

DATE(TIMESTAMP('1970-01-01','00.00.00') + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) ,

TIME( TIMESTAMP('1970-01-01-00.00.00') + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),

TIMESTAMP('1970-01-01-00.00.00') + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),

TIMESTAMP('1970-01-01-00.00.00')
CAST(t.timestampis as DECIMAL(31,0))/1000

from <table name>


This doesnot work...

There is a comma missing, it should be:

select
DATE(
TIMESTAMP('1970-01-01','00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) , TIME( TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),
TIMESTAMP('1970-01-01-00.00.00')
+ (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ),
TIMESTAMP('1970-01-01-00.00.00'), -- missing comma
CAST(t.timestampis as DECIMAL(31,0))/1000
from <table name>

Andy
Reply With Quote
  #14 (permalink)  
Old 05-05-09, 10:43
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
1) I thought that you want to add "TIMESTAMP(" like following code.
2) I want to recommend strongly to format your code with new line and indention(and use [code] tag to keep them on your post).
It will be usefull to find simple syntax errors(like missing or extra commas, unpaired parentheses, so on) on your code.
Code:
select
       DATE(
            TIMESTAMP('1970-01-01','00.00.00')
            + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) ,
       TIME(
            TIMESTAMP('1970-01-01-00.00.00')
            + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) ,
       TIMESTAMP(
            TIMESTAMP('1970-01-01-00.00.00')
            + (CAST(t.timestampis as DECIMAL(31,0))/1000) seconds ) ,
       TIMESTAMP('1970-01-01-00.00.00'), -- missing comma
       CAST(t.timestampis as DECIMAL(31,0))/1000
  from <table name>
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