Function to get number of weekdays between two dates excluding holidays

前端 未结 3 1140
南笙
南笙 2020-12-11 13:17

I have an sql query that casts 2 dates and checks if they are equal. But even though the dates are equal, i dont get the result.

create or replace 
FUNCTION          


        
3条回答
  •  难免孤独
    2020-12-11 14:16

    I am guessing that you are using Oracle. If so, the DATE data type contains a time component. This is rather confusing. But you could do what you want using TRUNC() rather than CAST():

    SELECT TRUNC(HOLIDAY_DATE), DATE '2011-04-16'  --into DAY_COUNT
    FROM ATL_JOB_HOLIDAY jh JOIN
         ATL_MASTER_JOB mj
         ON mj.MASTER_JOB_ID = jh.MASTER_JOB_ID
    WHERE TRUNC(HOLIDAY_DATE) = DATE '2011-04-16';
    

    Note also the preference for ANSI standard dates and for table aliases.

提交回复
热议问题