X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 89F06D1DD17 for ; Mon, 16 Feb 2004 13:04:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 05206-06 for ; Mon, 16 Feb 2004 09:04:22 -0400 (AST) Received: from rock.spider.ru (rock.spider.ru [62.183.34.226]) by svr1.postgresql.org (Postfix) with ESMTP id 25D0DD1DA97 for ; Mon, 16 Feb 2004 09:04:18 -0400 (AST) Received: from rock (localhost [127.0.0.1]) by rock (Postfix) with SMTP id BD5309127B for ; Mon, 16 Feb 2004 16:04:19 +0300 (MSK) Received: from sad.localnet.ru (sad.localnet.ru [10.0.0.33]) by rock.spider.ru (Postfix) with ESMTP id 5048291267 for ; Mon, 16 Feb 2004 16:04:19 +0300 (MSK) Content-Type: text/plain; charset="iso-8859-1" From: sad Organization: IT To: pgsql-sql@postgresql.org Subject: Re: Getting the week of a date Date: Mon, 16 Feb 2004 16:08:52 +0300 User-Agent: KMail/1.4.3 References: <00f701c3f485$d7091430$7502a8c0@hdsc.com> In-Reply-To: <00f701c3f485$d7091430$7502a8c0@hdsc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200402161608.52404.sad@bankir.ru> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/196 X-Sequence-Number: 16886 On Monday 16 February 2004 15:10, you wrote: > > Any idea on how to find the 3 rd Wednesday of any given month. SELECT=20 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 t= hat=20 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)