Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Broken down step-by-step. End of week left as an exercise

SELECT
  doy,
  EXTRACT(dow FROM doy) AS offset,
  (doy - EXTRACT(dow FROM doy) * '1 day'::interval)::date AS start_of_week
FROM
  (SELECT ('2008-01-04'::date + 8 * '1 week'::interval)::date AS doy)
AS foo;

    doy     | offset | start_of_week
------------+--------+---------------
 2008-02-29 |      5 | 2008-02-24
(1 row)

--
  Richard Huxton
  Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux