Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.9.3/8.9.3) with ESMTP id GAA79899 for ; Tue, 26 Oct 1999 06:33:28 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.8/8.8.8) with ESMTP id MAA19653; Tue, 26 Oct 1999 12:33:16 +0200 (IST) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <3814A06B.3BB61BA0@zotconsulting.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Tue, 26 Oct 1999 12:33:55 +0200 To: "Zot O'Connor" From: Herouth Maoz Subject: Re: [SQL] Week of year function? Cc: pgsql-sql@postgreSQL.org At 20:24 +0200 on 25/10/1999, Zot O'Connor wrote: > Herouth Maoz wrote: > > > > At 21:52 +0200 on 22/10/1999, Zot O'Connor wrote: > > > > > Is there a function to return the week of the year (0-51)? > > > > Seems you only need to divide the day of the year by seven to reach that, > > don't you? > > > > BTW I ought to offset the year to some standard too since Jan1 is not a > sunday. I know Intel starts work week 1 in dec this work year. That's why I asked whether you only needed to divide by seven. It depends on your definition of "a week". If you define a week as "seven consecutive days", then in a year with 365 or 366 days you will always have 53 weeks, the last of which being a short one. If you define a week as "Monday to Sunday", or "Sunday to Saturday" (this is culture-dependent), then you may even have 54 weeks per year (52 full weeks, a weekend in the beginning, and the beginning of a week in the end - but only in a leap year). This complicates the calculation a bit. You probably have to subtract the day-of-week (0-7) oy January first from it, and then subtract the resulting date from your $1, and divide by 7. This is true in places where the week's first day is Sunday. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma