Date Diff in Teradata

Database
Fan

Date Diff in Teradata

Hello All,

I have requiremnet to pull the data based upon +7 and -3 days between two dates parameters . both column are string format . Can you please confirm the Teradata code is correct or not ?

 

SQL code: datediff(Day,er.startdate,ep.enddate) between -3 and +7 

Teradata Code: CAST(er.startdate AS DATE)-CAST(ep.enddate AS DATE) BETWEEN -3 AND +7

Thanks,

CK

1 REPLY
Teradata Employee

Re: Date Diff in Teradata

Yes, that is how date arithmetic is done.  Just note that you may need to add a FORMAT phrase to the CAST function if startdate and enddate are not in the default format.
You can experiment with it thusly:

select case
	when cast('07/07/18' as date format'mm/dd/yy')-cast('06/30/18' as date format'mm/dd/yy') between -3 and +7
	then 1
	else 0
	end
;