Skip site navigation (1) Skip section navigation (2)

Re: How can I get the first and last date of a week, based on the week number and the year

From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How can I get the first and last date of a week, based on the week number and the year
Date: 2008-02-27 03:10:27
Message-ID: 200802261910.27752.aklaver@comcast.net (view raw or flat)
Thread:
Lists: pgsql-general
On Tuesday 26 February 2008 5:32 pm, Bruno Baguette wrote:
> Hello !
>
> I have a week number (ISO 8601) and a year, based on theses values, I
> would like to get the first and the last dates of that week.
>
> How I can do that ?
>
> The only solution is doing a big generate_series to build a subset that
> contains the week of all the dates between the 01/01 || year and the
> 31/12 || year. But I find that solution quite dirty and ressources
> consumming.
>
> Is there a cleanest way to do that ?
>
> Many thanks in advance !
>
> Regards,

This will get you to the Monday of the week .

select to_date('9  08','IW  YY');
  to_date
------------
 2008-02-25
(1 row)

Where 9 is the ISO week number and 08 is the year. See below for more details:
http://www.postgresql.org/docs/8.2/interactive/functions-formatting.html
-- 
Adrian Klaver
aklaver(at)comcast(dot)net

In response to

Responses

pgsql-general by date

Next:From: brianDate: 2008-02-27 03:21:04
Subject: Re: How can I get the first and last date of a week, based on the week number and the year
Previous:From: DeeDate: 2008-02-27 01:58:14
Subject: Re: Invalid username specified: A required privlege is not held by the client

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group