Oracle: Days between two date and Exclude weekdays how to handle negative numbers

Adapted from my answer here:

Get the number of days between the Mondays of both weeks (using TRUNC( datevalue, 'IW' ) as an NLS_LANGUAGE independent method of finding the Monday of the week) then add the day of the week (Monday = 1, Tuesday = 2, etc., to a maximum of 5 to ignore weekends) for the end date and subtract the day of the week for the start date. Like this:

SELECT ( TRUNC( end_date, 'IW' ) - TRUNC( start_date, 'IW' ) ) * 5 / 7
       + LEAST( end_date - TRUNC( end_date, 'IW' ) + 1, 5 )
       - LEAST( start_date - TRUNC( start_date, 'IW' ) + 1, 5 )
          AS WeekDaysDifference
FROM   your_table

Leave a Comment