Re: Work hours? - Mailing list pgsql-general

From Paul A Jungwirth
Subject Re: Work hours?
Date
Msg-id CA+renyVqJbkRhBwi70wvCqD1+Lf5SbjdgFSb-YFiJ0s+fxAnzQ@mail.gmail.com
Whole thread Raw
In response to Work hours?  (stan <stanb@panix.com>)
List pgsql-general
On Tue, Aug 27, 2019 at 3:27 PM stan <stanb@panix.com> 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



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Work hours?
Next
From: Rob Sargent
Date:
Subject: Re: Work hours?