Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 3EBCF4771F6 for ; Fri, 21 Jun 2002 14:32:00 -0400 (EDT) Received: from beamish.nsd.ca (unknown [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id E6A6B478D92 for ; Fri, 21 Jun 2002 13:45:22 -0400 (EDT) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id NAA14942; Fri, 21 Jun 2002 13:45:18 -0400 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma014938; Fri, 21 Jun 02 13:45:01 -0400 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id NAA06677; Fri, 21 Jun 2002 13:45:00 -0400 Message-ID: <3D13666B.AC687A4A@nsd.ca> Date: Fri, 21 Jun 2002 13:46:19 -0400 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.9-31 i686) X-Accept-Language: en MIME-Version: 1.0 To: josh@agliodbs.com Cc: pgsql-sql@postgresql.org Subject: Re: SQL Challenge: Skip Weekends References: <200206201713.03801.josh@agliodbs.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200206/300 X-Sequence-Number: 8265 here is the algorithm: date := now - day_of_the_week interval := interval + day_of_the_week date := date + int( interval/5)x7 + ( interval mod 5) Josh Berkus wrote: > > Folks, > > Hey, I need to write a date calculation function that calculates the date > after a number of *workdays* from a specific date. I pretty much have the > "skip holidays" part nailed down, but I don't have a really good way to skip > all weekends in the caluclation. Here's the ideas I've come up with: > > Idea #1: Use a reference table > 1. Using a script, generate a table of all weekends from 2000 to 2050. > 2. Increase the interval by the number of weekends that fall in the relevant > period. > > Idea #2: Some sort of calculation using 5/7 of the interval, adjusted > according to the day of the week of our starting date. My head hurts trying > to figure this one out. > > -- > -Josh Berkus > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster