dcsimg
timestamp conversion to DB2 format
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anchal_Agarwal
Posted On:   Tuesday, October 17, 2006 10:35 AM

Hi, I need to do a comparison on the timestamp column in my DB2 table. I'm using JDBC and need to execute the following SQL query: select * from myTable where TIMESTAMP_COL > '20062006-10-11-13.22.33.231934' Though this query works fine, the issue is that the timestamp value '2006-10-11-13.22.33.231934' is decided at run time and I'm not able to get the time in the required format. I tried the following statement to get a formatted timestamp value: String timestamp = new Timestamp(System.currentTimeMillis())).toString(); But this statement gives me the timestamp in 2006-10-17 19:39:56.933 format and when I run the query with this    More>>

Hi,


I need to do a comparison on the timestamp column in my DB2 table. I'm using JDBC and need to execute the following SQL query:


select * from myTable where TIMESTAMP_COL > '20062006-10-11-13.22.33.231934'


Though this query works fine, the issue is that the timestamp value '2006-10-11-13.22.33.231934'
is decided at run time and I'm not able to get the time in the required format.


I tried the following statement to get a formatted timestamp value:


String timestamp = new Timestamp(System.currentTimeMillis())).toString();


But this statement gives me the timestamp in 2006-10-17 19:39:56.933 format and when I run the query with this value, I get the following error:


SQL0181N The string representation of a datetime value is out of range.


SQLSTATE=22007


May I please know how I can get the timestamp in the correct format?


Thanks in advance,


Anchal.

   <<Less

Re: timestamp conversion to DB2 format

Posted By:   Anchal_Agarwal  
Posted On:   Thursday, October 26, 2006 12:42 AM

I replaced


String timestamp = new Timestamp(System.currentTimeMillis())).toString();


with


SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS");


String timestamp = simpleDateFormat.format(new Timestamp(System.currentTimeMillis()));


This worked.


Thanks,


Anchal

About | Sitemap | Contact