Re: [SQL] Week of year function?

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: "Zot O'Connor" <zot(at)zotconsulting(dot)com>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Week of year function?
Date: 1999-10-26 10:33:55
Message-ID: l03130300b43b2e7ab424@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Juarez Rudsatz 1999-10-26 11:16:08 Re: pgsql-sql-digest V1 #393
Previous Message John Ridout 1999-10-26 08:24:09 RE: [SQL] Access and field sizes