days Difference between 2 date fields in Teradata SQL

Database

days Difference between 2 date fields in Teradata SQL

HI All,

 

I have 2 fields in my Table - 'Snap_date' and 'Open_date'. Both fields are in the same format - 'mm/dd/yyyy'. I want to find the difference between these 2 fields in no,of Days and put it as a new column as 'Diff date'.

2 REPLIES
Teradata Employee

Re: days Difference between 2 date fields in Teradata SQL

If they are both data type DATE, then just subtract them.  Otherwise cast them as date and subtract, e.g.,

Select ..., ( cast(Snap_date as date format'mm/dd/yy') - cast(Open_date as date format'mm/dd/yy') ) as "Diff date", ...

Teradata Employee

Re: days Difference between 2 date fields in Teradata SQL

if the column types are both DATE then you should be able to just subtract >

Select 'Snap_date' - 'Open_date'  from table;

 

you could create a view and include the column DIFF_DAYS with the subtraction