On Tue, Aug 27, 2019 at 3:27 PM stan <stanb@xxxxxxxxx> wrote: > I need to write a function that, given a month, and a year as input returns > the "work hours" in that month. In other words something like > > 8 * the count of all days in the range Monday to Friday) within that > calendar month. This gives you all the weekdays in August 2019: select t::date from generate_series('2019-08-01'::date, '2019-09-01'::date, interval '1 day') s(t) where extract(dow from t) not in (0, 6); >From there you could count & multiply by 8 (e.g. `select count(*) * 8` instead). You'll probably want to remove holidays first though. If those lived in another table you could do a NOT EXISTS to remove them before you count. Yours, Paul