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 > timestamp format incorrect?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-26-10, 14:37
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
timestamp format incorrect?

Hi,

Can you please tell what I'm doing wrong here? Thanks!!

db2 "select TIMESTAMP(CHAR(DATE(CURRENT TIMESTAMP), ISO), TIME(CHAR(HOUR(CURRENT TIMESTAMP)) || '.' || CHAR('00') || '.' || CHAR('00'))) from sysibm.sysdummy1"

1
--------------------------
SQL0180N The syntax of the string representation of a datetime value is
incorrect. SQLSTATE=22007



This looks good --

db2 "select TIMESTAMP(CHAR(DATE(CURRENT TIMESTAMP), ISO), TIME(CHAR('00') || '.' || CHAR('00') || '.' || CHAR('00'))) from sysibm.sysdummy1"

1
--------------------------
2010-10-26-00.00.00.000000

1 record(s) selected.
Reply With Quote
  #2 (permalink)  
Old 10-26-10, 14:54
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
CHAR(HOUR(CURRENT TIMESTAMP)) includes trailing blanks, like this:

Code:
------------------------------ Commands Entered ------------------------------
select CHAR(HOUR(CURRENT TIMESTAMP)) || '.' || CHAR('00') || '.' || CHAR('00') from sysibm.sysdummy1;
------------------------------------------------------------------------------

1                
-----------------
3          .00.00

  1 record(s) selected.
Use VARCHAR rather than CHAR, like...

Code:
------------------------------ Commands Entered ------------------------------
select TIMESTAMP(CHAR(DATE(CURRENT TIMESTAMP), ISO), TIME(VARCHAR(HOUR(CURRENT TIMESTAMP)) || '.' || CHAR('00') || '.' || CHAR('00'))) from sysibm.sysdummy1;
------------------------------------------------------------------------------

1                         
--------------------------
2010-10-27-03.00.00.000000

  1 record(s) selected.
Reply With Quote
  #3 (permalink)  
Old 10-26-10, 15:04
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
thanks, I get this now --

db2 "select TIMESTAMP(CHAR(DATE(CURRENT TIMESTAMP), ISO), TIME(VARCHAR(HOUR(CURRENT TIMESTAMP)) || '.' || CHAR('00') || '.' || CHAR('00'))) from sysibm.sysdummy1"
SQL0440N No authorized routine named "VARCHAR" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884



btw, am using version 8.2 Db2 UDB
Reply With Quote
  #4 (permalink)  
Old 10-26-10, 15:13
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
btw, am using version 8.2 Db2 UDB
So, try RTRIM(CHAR(HOUR(CURRENT TIMESTAMP))), like ...

Code:
------------------------------ Commands Entered ------------------------------
select TIMESTAMP(CHAR(DATE(CURRENT TIMESTAMP), ISO), TIME(RTRIM(CHAR(HOUR(CURRENT TIMESTAMP))) || '.' || CHAR('00') || '.' || CHAR('00'))) from sysibm.sysdummy1;
------------------------------------------------------------------------------

1                         
--------------------------
2010-10-27-04.00.00.000000

  1 record(s) selected.
Reply With Quote
  #5 (permalink)  
Old 10-26-10, 15:45
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
If you want to get truncated timestamp, here is an example.

Code:
------------------------------ Commands Entered ------------------------------
select TIMESTAMP( SUBSTR(CHAR(CURRENT TIMESTAMP), 1, 14) || '00.00' ) from sysibm.sysdummy1;
------------------------------------------------------------------------------

1                         
--------------------------
2010-10-27-04.00.00.000000

  1 record(s) selected.
Reply With Quote
  #6 (permalink)  
Old 10-26-10, 16:29
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Quote:
Originally Posted by tonkuma View Post
If you want to get truncated timestamp, here is an example.

Code:
------------------------------ Commands Entered ------------------------------
select TIMESTAMP( SUBSTR(CHAR(CURRENT TIMESTAMP), 1, 14) || '00.00' ) from sysibm.sysdummy1;
------------------------------------------------------------------------------

1                         
--------------------------
2010-10-27-04.00.00.000000

  1 record(s) selected.


great! thanks..this is perfect!
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