Here are the examples of Oracle SQL queries to exclude weekends from a date range.
Suppose you are querying a table to get the data for a particular date range, and you want to exclude the weekends. Below is an example.
Exclude Weekends in Oracle SQL Using to_char(date, 'DY') Function
The following SQL query will get the last 30 days' sales data, but weekends (Saturdays and Sundays) are excluded:
SELECT * FROM sales_orders WHERE TO_CHAR(order_date, 'DY') NOT IN ('SAT', 'SUN') and trunc(order_date) >= trunc(sysdate) - 30;
The data output will include all days except Saturdays and Sundays.