Date Diff in Teradata

Tools
Enthusiast

Date Diff in Teradata

Hi,
can one help me in finding the diff between two dates in Teradata excluding saturdays and sundays.
Thanks in advance.
2 REPLIES
Enthusiast

Re: Date Diff in Teradata

select (current_date - date '2007-04-01') - count(calendar_date) from sys_calendar.calendar where day_of_week in (1,7) and calendar_date between date '2007-04-01' and current_date;

The above query would return 18 leaving out the 7 week end dates:

04-01-2007
04-07-2007
04-08-2007
04-14-2007
04-15-2007
04-21-2007
04-22-2007

Re: Date Diff in Teradata

Hi, I have a simliar issue with my code. This is TSQL code which I can transfer to teradata. The issue is:

I have a table with CUSTID, ORDERID, ORDERDATE.  I wrote a code but it is giving me the difference between first two  transcations for each customer. I am trying to find the difference between every two consequetive transactions made by each customer. Please help.

select a.custid, a.orderid, b.orderid as orderid2, a.orderdate as date1, b.orderdate as date2,

row_number() over(partition by a.custid order by a.custid, a.orderid) as order_rank

from Sales.Orders as a inner join Sales.Orders as b

on a.custid=b.custid

where a.orderid <b.orderid) t1

where t1.order_rank <2

order by custid, order_rank;