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 date format problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-28-09, 05:24
ashrash ashrash is offline
Registered User
 
Join Date: Aug 2009
Posts: 15
Red face db2 date format problem

hi
everyone

i m new to this website.after long searching i found this site is useful.i have a problem in db2


i want to the date from db2 in this format dd-mon-yy

can anyone pls tell me the soultion i have tried

this from ibm db2 site but this also not working
SELECT VARCHAR_FORMAT(CURRENT TIMESTAMP,'DD-MON-YYYY HH24:MIS') FROM SYSIBM.SYSDUMMY1

i have tried the other way also using substring and date then count ...bla bla..

i dont want this confused query .....since i m in field of databse administrating

can anyone tell me whats the problem inthis query



db2 => SELECT VARCHAR_FORMAT(CURRENT TIMESTAMP,'DD-MON-YYYY HH24:MIS') FROM SYSIBM.SYSDUMMY1
SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.VARCHAR_FORMAT" is incorrect. SQLSTATE=42815
Reply With Quote
  #2 (permalink)  
Old 08-28-09, 05:41
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
'DD-MON-YYYY HH24:MIS'
is not a proper format.... MM should be there

try playing with monthname/ day / year/ concat functions to get desired result
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #3 (permalink)  
Old 08-28-09, 07:37
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
The format 'DD-MON-YYYY HH24:MI:SS' is supported on DB2 9.7 for LUW.
If you are using other platform or older DB2 version, the way of rahul_s80 would be a solution.

Here is an example:
Code:
------------------------------ Commands Entered ------------------------------
connect to SAMPLE ;
------------------------------------------------------------------------------

   Database Connection Information

 Database server        = DB2/NT 9.7.0
 SQL authorization ID   = DB2ADMIN
 Local database alias   = SAMPLE


A JDBC connection to the target has succeeded.
------------------------------ Commands Entered ------------------------------
SELECT VARCHAR_FORMAT(CURRENT TIMESTAMP,'DD-MON-YYYY HH24:MI:SS') FROM SYSIBM.SYSDUMMY1;
------------------------------------------------------------------------------

1                                       
----------------------------------------
28-AUG-2009 20:36:07                    

  1 record(s) selected.
Reply With Quote
  #4 (permalink)  
Old 08-28-09, 08:46
ashrash ashrash is offline
Registered User
 
Join Date: Aug 2009
Posts: 15
thank you tonkuma

but this command is not working because i m using db2 9.1 version


it is giving error
SQL0171N The data type, length or value of argument "2" of routine
"SYSIBM.VARCHAR_FORMAT" is incorrect. SQLSTATE=42815
Reply With Quote
  #5 (permalink)  
Old 08-28-09, 09:22
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
I already wrote:
Quote:
If you are using other platform or older DB2 version, the way of rahul_s80 would be a solution.
Reply With Quote
  #6 (permalink)  
Old 08-28-09, 09:46
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Is this what you need?

Code:
db2 "SELECT char(date(CURRENT TIMESTAMP),local) FROM SYSIBM.SYSDUMMY1"

1         
----------
08-28-2009

  1 record(s) selected.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #7 (permalink)  
Old 08-28-09, 10:06
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
i want to the date from db2 in this format dd-mon-yy
Here is an example:
Code:
------------------------------ Commands Entered ------------------------------
SELECT INSERT(CHAR(CURRENT DATE, EUR), 3, 6, '-'||LEFT(MONTHNAME(CURRENT DATE), 3)||'-') FROM SYSIBM.SYSDUMMY1;
------------------------------------------------------------------------------

1                                                                                                               
----------------------------------------------------------------------------------------------------------------
28-Aug-09                                                                                                       

  1 record(s) selected.
Reply With Quote
  #8 (permalink)  
Old 08-28-09, 22:07
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Here is another option:

select substr(current_date,9,2)||'-'||substr(monthname(current_date),1,3)||'-'||substr(current_date,1,4) from sysibm.sysdummy1

The DB2 scaler funcitons are described in the SQL Reference Vol 1, or search on "scaler functions" in the DB2 InfoCenter.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #9 (permalink)  
Old 08-29-09, 03:54
ashrash ashrash is offline
Registered User
 
Join Date: Aug 2009
Posts: 15
thanks everyone

yeah its working


i have checked using

SELECT INSERT(CHAR(CURRENT DATE, EUR), 3, 6, '-'||LEFT(MONTHNAME(CURRENT DATE), 3)||'-') FROM SYSIBM.SYSDUMMY1

but it is not working by using varchar_format and to char format

may be db2 version problem


still i m not sure whether it is version problem anyway thanks all my experienced friends
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