Reputation: 496
I'm trying to calculate the difference in business days between two dates, at my searches I found the use of functions and gereneate_series() but I would like to search something more practical.
Sample Table:
|start_date |end_date |
|2022-06-01 |2022-06-01|
|2022-05-29 |2022-06-02|
Upvotes: 1
Views: 1845
Reputation: 14934
What would you consider more practical? It seems generate_series
and extract
are specifically made for what you are asking. (see demo)
select start_date, end_date, count(*) "Business days"
from sometable
cross join generate_series(start_date,end_date,interval '1 day') gs(dt)
where extract(isodow from dt) < 6
group by start_date, end_date;
Upvotes: 2