Re: Getting the week of a date

From: sad <sad(at)bankir(dot)ru>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Getting the week of a date
Date: 2004-02-16 13:08:52
Message-ID: 200402161608.52404.sad@bankir.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Monday 16 February 2004 15:10, you wrote:
>
> Any idea on how to find the 3 rd Wednesday of any given month.

SELECT
1-(to_char(date_trunc('month', now()::timestamp),'D'))::INT2 + 7*3-3

replace now with any date and you'll the the day number of a third Wed in that
month.

7 is a constant (factor 3 is a desired week number)
-3 is number of days to step back from sunday to a desired day of week
(-3 stands for Wed)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message sad 2004-02-16 13:23:24 Re: Getting the week of a date
Previous Message Mark Roberts 2004-02-16 13:06:22 Date format problems