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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to