difference between two dates without weekends and holidays Sql query ORACLE -
i have 2 tables: 1st 1 contains start date , end date of purchase order, , 2nd table contains year hollidays
-purchase order
-holidays
i'm tryign calculate number of business days between 2 dates without weekends , holidays.
the output should this:
start date | end date | business days
could please me
you can remove non-weekend holidays query this:
select (t.end_date - t.start_date) - count(c.date) table1 t left join calendar c on c.date between t1.start_date , t1.end_date , to_char(c.date, 'd') not in ('1', '7') group t.end_date, t.start_date;
removing weekend days more complication. full weeks have 2 weekend days, easy. approximation is:
select (t.end_date - t.start_date) - (count(c.date) + 2 * floor((t.end_date - t.start_date) / 7)) table1 t left join calendar c on c.date between t1.start_date , t1.end_date , to_char(c.date, 'd') not in ('1', '7') group t.end_date, t.start_date;
this doesn't day of week, if end date before start date, in following week. however, logic gets rather complicated way oracle handles day of week, perhaps above approximation sufficient.
Comments
Post a Comment