Reputation: 161
How do I go about calculating number of workdays in a MONTH based on a date in another column?
Example: Column 1 - 2020-06-30 Column 2 (Calculated) - 22 (i.e number of workdays in the month of June Mon to Friday)
Does BQ have a WORKDAY function?
Upvotes: 1
Views: 1321
Reputation: 172944
You can use below approach
create temp function workdays(input date) as ((
select count(*)
from unnest(generate_date_array(date_trunc(input, month), last_day(input, month ))) day
where not extract(dayofweek from day) in (1, 7)
));
select column1,
workdays(column1) as column2
from your_table
if applied to sample data in your question - output is
Upvotes: 2