Datediff function in Teradata

Database
Enthusiast

Datediff function in Teradata

Hi all, i have a column Deposit_Date with date type like '1997-08-17 03:43:00.000' and i need to run this code: 

...

where DATEDIFF(day,Deposit_Date,GETDATE())>=2 

 

i can't find right conversion in TD

 

any help?

 

BR

2 REPLIES
Enthusiast

Re: Datediff function in Teradata

what about this one:

(cast(First_Deposit_Date as date)- cast(CURRENT_TIMESTAMP as date)) >= 2)   ?

 

Senior Apprentice

Re: Datediff function in Teradata

You current logic is not SARGable (= searchable argument), i.e. you loose index access & statistics. 

Rewrite it to 

WHERE Deposit_Date <= Current_Date -2

Comparing Timestamp and Date automatically converts the Timestamp to a date.

 

Even better, switch to a Timestamp

WHERE Deposit_Date < Cast(Current_Date -1 AS TIMESTAMP) -- caution: -1, not -2