| |
|
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.
|
 |

03-19-10, 04:26
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 200
|
|
|
data format
|
|
hi
table is having a column which has a data type char
but contains date in it
eg:
JT_DT char(10)
'2002-04-18'
can i convert it into 04-18-2002 in any ways like can we write
a stored procedure
rregds
Pual
|
|

03-19-10, 09:39
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,473
|
|
Can you elaborate on what you want to do? Also include the DB2 version and OS you are using.
Andy
|
|

03-19-10, 10:59
|
|
Registered User
|
|
Join Date: May 2009
Posts: 457
|
|
|
|
mathew paul, if the value in JT_DT is really a Date, the datatype should be DATE and not CHAR(10). This allows you to use Date functions with less effort and it will take up less storage space (4 bytes compared to 10 bytes). And since DB2 stores Dates (and Time and Timestamps) in a modified pack format, you can display it in any of the standard DB2 formats with:
CHAR(JT_DT, USA)
The formats are ISO/JIS yyyy-mm-dd, USA mm/dd/yyyy or EUR dd.mm.yyyy
However, if this can't be changed or you really want the output in a non-standard DB2 format of dd-mm-yyyy you can use SUBSTR to get what you want:
SUBSTR(JT_DT,6,2) CONCAT '-' CONCAT SUBSTR(JT_DT,9,2) CONCAT '-' CONCAT SUBSTR(JT_DT,1,4)
|
|

03-19-10, 12:11
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 1,827
|
|
Some othet expressions.
Code:
------------------------------ Commands Entered ------------------------------
SELECT jt_dt
, SUBSTR(jt_dt, 6, 5) || '-' || SUBSTR(jt_dt, 1, 4) expression_1
, TRANSLATE('ef-gh-abcd', jt_dt, 'abcd-ef-gh') expression_2
, REPLACE(CHAR(DATE(jt_dt), USA), '/', '-') expression_3
, RIGHT(jt_dt, 5) || '-' || LEFT(jt_dt, 4) expression_4
FROM (VALUES CAST('2002-04-18' AS CHAR(10) ) ) AS s(jt_dt)
;
------------------------------------------------------------------------------
JT_DT EXPRESSION_1 EXPRESSION_2 EXPRESSION_3 EXPRESSION_4
---------- ------------ ------------ ------------ ---------------------
2002-04-18 04-18-2002 04-18-2002 04-18-2002 04-18-2002
1 record(s) selected.
|
|

03-19-10, 12:24
|
|
Registered User
|
|
Join Date: Jul 2009
Location: NY
Posts: 816
|
|
Quote:
Originally Posted by Mathew_paul
hi
table is having a column which has a data type char
but contains date in it
eg:
JT_DT char(10)
'2002-04-18'
can i convert it into 04-18-2002 in any ways like can we write
a stored procedure
rregds
Pual
|
It's easy:
Code:
select replace(char(date('2002-04-18'), USA), '/', '-')
from sysibm.sysdummy1
Lenny
|
|

03-20-10, 04:57
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 200
|
|
thks for reply
i did this way
select substr(del_dt),9,2)||'-'||substr(del_dt),6,2)||'-'||substr(del_dt),1,4) from tabname
it worked
regs
paul
|
|

03-20-10, 05:16
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 1,827
|
|
Quote:
|
select substr(del_dt),9,2)||'-'||substr(del_dt),6,2)||'-'||substr(del_dt),1,4) from tabname
|
So, do you want '18-04-2002' from '2002-04-18'?
It's different from original post.
Quote:
eg:
JT_DT char(10)
'2002-04-18'
can i convert it into 04-18-2002 in any ways.....
|
|
|

03-20-10, 06:58
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 1,827
|
|
If you want '18-04-2002' from '2002-04-18',
here are two other ways.
Code:
------------------------------ Commands Entered ------------------------------
SELECT jt_dt
, TRANSLATE('gh-ef-abcd', jt_dt, 'abcd-ef-gh') expression_2
, REPLACE(CHAR(DATE(jt_dt), EUR), '.', '-') expression_3
FROM (VALUES CAST('2002-04-18' AS CHAR(10) ) ) AS s(jt_dt)
;
------------------------------------------------------------------------------
JT_DT EXPRESSION_2 EXPRESSION_3
---------- ------------ ------------
2002-04-18 18-04-2002 18-04-2002
1 record(s) selected.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|