正如标题所说,我想在Oracle中计算两个日期之间的天数并排除周末(周六和周日),我根本不知道这一点,有人可以帮助提供示例SQL吗?
答案 0 :(得分:1)
试试这个。根据您的要求更改start_date和end_date。
如果您想要工作日数,请使用
$scope.event.start = new Date(2010, 11, 28, 14, 57);
如果要显示日期,请在select子句中使用
WITH test_data AS
(
SELECT TO_DATE('01-JAN-2014','DD-MON-YYYY') AS start_date,
TO_DATE('31-DEC-2014','DD-MON-YYYY') AS end_date
FROM dual
),
all_dates AS
( SELECT td.start_date, td.end_date, td.start_date + LEVEL-1 as week_day
FROM test_data td
CONNECT BY td.start_date + LEVEL-1 <= td.end_date)
select count(*) from all_dates
WHERE to_char(week_day, 'dy', 'nls_date_language=AMERICAN') NOT IN ('sun' , 'sat')
工作原理:
select week_day from all_dates
/ end_date
,开始向start_date添加1天,直至到达connect by
。level
或saturday
PS:为此提及answer
答案 1 :(得分:0)
如何简化
“选择*来自emp之间的雇用 To_date(f_date,'dd-mm-yyyy)和to_date(t_date, 'Dd-mm-yyyy')和to_char(hiredate,dy)不在('sat','sun')