Re: workday function - Mailing list pgsql-sql

From Richard Huxton
Subject Re: workday function
Date
Msg-id 464978C0.2050004@archonet.com
Whole thread Raw
In response to workday function  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
Responses Re: workday function  (Kenneth Gonsalves <lawgon@thenilgiris.com>)
List 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 by date:

Previous
From: Gary Stainburn
Date:
Subject: workday function
Next
From: Richard Huxton
Date:
Subject: Re: workday function