Re: workday function

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: workday function
Дата
Msg-id 464978C0.2050004@archonet.com
обсуждение исходный текст
Ответ на workday function  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
Ответы Re: workday function  (Kenneth Gonsalves <lawgon@thenilgiris.com>)
Список pgsql-sql
Gary Stainburn wrote:
> Hi folks
> 
> I need to be able to add and subtract workdays, something like
> 
> select CURRENT_DATE - '3 work days'::interval;
> 
> I can't see how to do this natively so I'm looking to write a function to do 
> it and was wondering if anyone's already done it.

Don't know of one - not sure what "workday" would mean in a global 
sense. I mean, Mon-Fri in most European office settings, but you'd 
include Sat in retail settings and in Islamic countries presumably 
exclude Fridays. Our local library shuts early on Mondays iirc but is 
open Saturday mornings.

Casting to interval won't work because work-days will be a variable 
amount of real-days based on what you're adding/subtracting from.

> While Googling I've found that MS Excel has a workday function which seems to 
> do what I want.
> 
> Any help would be appreciated.

Well, you'll be wanting to use extract('dow' from current_date) or 
similar to figure out how many days to skip. There are national-holiday 
resources online, but I'm not sure if they take into account e.g. the 
extra day civil servants get in the UK (or used to) for the Queen's 
official birthday.

--   Richard Huxton  Archonet Ltd


В списке pgsql-sql по дате отправления:

Предыдущее
От: Gary Stainburn
Дата:
Сообщение: workday function
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: workday function