Current_timestamp issue

Training
Enthusiast

Current_timestamp issue

hi all

 

DT_Date_ID >= CAST(CAST(((CURRENT_TIMESTAMP -interval '7'   day)(FORMAT 'YYYYMMDD')) AS VARCHAR(100)) AS INTEGER)

this code is working fine, but i need interval of different days (from Days_Back column) - what is exact syntax for this in TD, because mine below not works:(((

 

DT_Date_ID >= CAST(CAST(((CURRENT_TIMESTAMP -interval 'tt_table.Days_Back'  day)(FORMAT 'YYYYMMDD')) AS VARCHAR(100)) AS INTEGER)

 

 

2 REPLIES
Senior Apprentice

Re: Current_timestamp issue

Try

cast(tt_table.Days_Back as interval day(4))

But why do you use CURRENT_TIMESTAMP instead of CURRENT_DATE, then it's a simple

CURRENT_DATE - tt_table.Days_Back

 

Another way to get YYYYMMDD as integer without intermediate string:

cast(current_date - tt_table.DaysBack as int) + 19000000
Enthusiast

Re: Current_timestamp issue

CURRENT_DATE - tt_table.Days_Back is worked, thanks a lot!