将7天添加为字符串格式的日期

时间:2019-12-19 19:22:47

标签: teradata

我的表格中有一个varchar日期,格式为20060918,我希望能够在此日期前添加7天,并使其保持有效(如果我尝试将其设为+7,则会给我一个无效的日期) 这是我的代码

SELECT cast (WD.Adjusted_Hire_Date as date format 'YYYY-MM-DD')+ INTERVAL '7' DAY
from Analytics.Workday as WD;

但我遇到错误

Executed as Single statement.  Failed [2666 : 22007] Invalid date supplied for Workday.Adjusted_Hire_Date. 

我应该先转换Adjusted_Hire_Date列吗?

1 个答案:

答案 0 :(得分:0)

insert into Workday (employee_id,Adjusted_Hire_Date) select '3','20060918';

SELECT WD.Adjusted_Hire_Date 
  ,cast (trim(WD.Adjusted_Hire_Date) as date format 'YYYYMMDD')+ 7
from Workday as WD where employee_id=3;

Result:

[Adjusted_Hire_Date]    [Adjusted_Hire_Date+7]

20060918                9/25/2006