pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sad <sad@bankir.ru>
To: pgsql-sql@postgresql.org
Subject: Re: Getting the week of a date
Date: Mon, 16 Feb 2004 16:08:52 +0300
Message-ID: <200402161608.52404.sad@bankir.ru> (raw)
In-Reply-To: <00f701c3f485$d7091430$7502a8c0@hdsc.com>
References: <00f701c3f485$d7091430$7502a8c0@hdsc.com>

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)





view thread (7+ messages)  latest in thread

Message-ID: <200402161608.52404.sad@bankir.ru>
Permalink:  ../200402161608.52404.sad@bankir.ru/
Also on:    postgresql.org/message-id/200402161608.52404.sad@bankir.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sad@bankir.ru
  Subject: Re: Getting the week of a date
  In-Reply-To: <200402161608.52404.sad@bankir.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox