Error while converting date to char

Database
KVB
Enthusiast

Error while converting date to char

I have a table with date value stored in a char(10) format

CT KVB_DT(MYDATE CHAR(10))

INS INTO KVB_DT VALUES('20130620')

I need to add 7 days to it and it should be in char format as 20130627

I am able to add 7 days by converting it to date

SEL MYDATE,CAST(MYDATE AS DATE FORMAT 'YYYYMMDD') +INTERVAL '7' DAY  FROM KVB_DT

problem here is when I am trying to convert it it to char format.

SEL MYDATE,CAST(CAST(MYDATE AS DATE FORMAT 'YYYYMMDD') +INTERVAL '7' DAY AS CHAR(10) FORMAT 'YYYYMMDD') FROM KVB_DT

It is throwing error  YYYYMMDDdoesnt match the data type

2 REPLIES
Teradata Employee

Re: Error while converting date to char

SELECT MYDATE,CAST(CAST(CAST(MYDATE AS DATE FORMAT 'YYYYMMDD') +INTERVAL '7' DAY AS FORMAT 'YYYYMMDD') as CHAR(10))  FROM KVB_DT

KVB
Enthusiast

Re: Error while converting date to char

Thank you.