Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a problem when I try converting data from column name:'date'(string: ddmmyyyy ex:09032015) to fomat datetime (DD/MM/YYYY) and I'm using provider IBMDA400.

I use some commands to try converting but have not been successful.

My purpose is only select data from database but Visual Studio always displays error.

ex:

Cmd1: select date(to_date(my string,'dd/mm/yyyy') from table
-> In here appear error: SQ20448: Expression not valid using format string specified for TIMESTAMP_FORMAT.

And I changed: 'TIMESTAMP_FORMAT' instead of 'TO_DATE'
cmd2: select TIMESTAMP_FORMAT(mystring, 'DD/MM/RRRR HH24:MI')
-> Error SQ20448 continue to occur.
pls help me!!
thanks so much :D
Posted
Updated 2-Jan-20 2:51am

As you have a date stored in string in the format of DDMMYYYY, first you have to convert it into a real date:
SQL
DATE(TO_DATE(date_string, 'DDMMYYYY'))

The result is a binary date and can be converted to any string now...
SQL
CHAR(DATE(TO_DATE(date_string, 'DDMMYYYY')), USA)

AS400 has only pre-defined formats, so 'USA' will give you MM/DD/YYYY instead of DD/MM/YYYY...You may try 'EUR' that will give DD.MM.YYYY and than replace . (dot) to / (slash)...
Check other options here: http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/db2/rbafzmstch2func.htm[^]
 
Share this answer
 
Comments
haipt232 9-Mar-15 4:30am    
thank for your answer :D and i can convert successfully .
if i try 'EUR' that will give DD.MM.YYYY but you can support me how can i replace .(dot) to /(slash)
My code:
select CHAR(DATE(TO_DATE(Day || Month || Year ,'DDMMYYYY')),USA) as Datetime from table.
Because I have 3 fields (field 1:Day, field2: Month , Filed3: Year).And I grouped them 1 field like select command above.
Thanks
Kornfeld Eliyahu Peter 9-Mar-15 4:59am    
https://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c0925083585.htm
SQL
REPLACE(CHAR(DATE(TO_DATE(a.SCFVAL, 'YYYYMMDD')), EUR),'.','-') AS mydate<pre lang="SQL">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900