DB2 Convert from YYYYMMDD to Date
56,025
SELECT TIMESTAMP_FORMAT("DATEFIELD",'YYYYMMDD') as "MyDate"
Author by
Chry007
Programmer and Consultant at mid to large scale IT-Projects in Germany.
Updated on September 16, 2020Comments
-
Chry007 over 3 years
I have a column that stores a date as char in the format 'YYYYMMDD'. Now I want to convert it to a real date. I tried
select cast (DATEFIELD as DATE) as MyDate
But it only returns the old
YYYYMMDD
format labeled as 'DATE'. What am I doing wrong? -
Chry007 almost 9 yearsI tried your second suggestion but I get: NO AUTHORIZED CONVERT NAMED HAVING COMPATIBLE ARGUMENTS WAS FOUND SQL Code: -440, SQL State: 42884
-
Asha about 7 yearsthis answer will alter the data table where the question is about how to get the data column converted.
-
Hogan over 6 yearsThis is sql server not db2
-
Asha over 6 years@Hogan: The answer has been edited since my comment, Please take a look at edits. My commnet was relevant when there was an Alter statement.
-
Gnqz over 6 years@Hogan The question was also different, I really changed my answer since it was not relevant to the question anymore. Sorry for misguiding you.
-
Hogan over 6 years@Asha -- ugh sorry about that, I didn't look at the history.
-
Paul almost 6 yearsOn the iSeries, I'd sometimes have problems with TIMESTAMP_FORMAT and instead use TO_DATE