date format coverting



IBM's flagship relational database management system

date format coverting

Postby mfraj81 » Mon Jan 31, 2011 11:52 am

Hi all,

I have a field which stores the date in the format 'yyyymmdd'. I required to split it into 'yyyy-mm-dd'. Could you please let me help me with correct query?
mfraj81
 
Posts: 7
Joined: Thu Jan 27, 2011 2:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: date format coverting

Postby mfraj81 » Mon Jan 31, 2011 11:54 am

Hi all,

I have a field which stores the date in the format 'yyyymmdd'. I required to split it into 'yyyy-mm-dd'. Could you please help me with correct query?
mfraj81
 
Posts: 7
Joined: Thu Jan 27, 2011 2:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: date format coverting

Postby alexm » Mon Jan 31, 2011 8:51 pm

You may try this - however, it might be time consuming, depending on how much data you're going to process:
SELECT SUBSTR(Colname,1,4) CONCAT '-' CONCAT
       SUBSTR(Colname,5,2) CONCAT '-' CONCAT
       SUBSTR(Colname,7,2)                 
FROM   your-table
WHERE  ... ;                               
User avatar
alexm
 
Posts: 35
Joined: Wed Oct 13, 2010 6:40 pm
Has thanked: 0 time
Been thanked: 0 time

Re: date format coverting

Postby mfraj81 » Tue Feb 01, 2011 4:24 pm

Thank you it's working.
mfraj81
 
Posts: 7
Joined: Thu Jan 27, 2011 2:03 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post