Re: Extract week from date, start with sunday

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Extract week from date, start with sunday
Date: 2005-11-07 14:27:48
Message-ID: 20051107142748.GW9910@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

am 07.11.2005, um 14:47:35 +0100 mailte Robert Blixt folgendes:
>
> Hi,
>
>
> I am currently extracting my weeks from a date like this..
>
> SELECT INTO extractweek EXTRACT( week FROM ldate );
>
> This works fine, except that this assumes (according
> to ISO standard) that weeks starts with Monday.
>
> I need the weeks to start with Sunday instead, otherwise
> I will not get the correct week.
>
> Is there a workaround for this?

Add 1 day to ldate.

test=# select to_char('2005-11-05'::date+'1 day'::interval, 'IW');
to_char
---------
44
(1 row)

test=# select to_char('2005-11-06'::date+'1 day'::interval, 'IW');
to_char
---------
45
(1 row)

HTH, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47212, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Blixt 2005-11-08 06:52:57 Re: Extract week from date, start with sunday
Previous Message Robert Blixt 2005-11-07 13:47:35 Extract week from date, start with sunday