From: | Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com> |
---|---|
To: | stan <stanb(at)panix(dot)com> |
Cc: | pgsql <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Work hours? |
Date: | 2019-08-27 22:59:55 |
Message-ID: | CA+renyVqJbkRhBwi70wvCqD1+Lf5SbjdgFSb-YFiJ0s+fxAnzQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Aug 27, 2019 at 3:27 PM stan <stanb(at)panix(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2019-08-27 23:12:22 | Re: Work hours? |
Previous Message | Adrian Klaver | 2019-08-27 22:59:12 | Re: Work hours? |