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 9C4A8D1DAB1 for ; Tue, 17 Feb 2004 05:09:46 +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 18566-01 for ; Tue, 17 Feb 2004 01:09:39 -0400 (AST) Received: from smtp018.mail.yahoo.com (smtp018.mail.yahoo.com [216.136.174.115]) by svr1.postgresql.org (Postfix) with SMTP id 33C33D1D174 for ; Tue, 17 Feb 2004 01:09:38 -0400 (AST) Received: from unknown (HELO IVESIA67) (sgnerd@203.196.190.138 with login) by smtp018.mail.yahoo.com with SMTP; 17 Feb 2004 05:09:36 -0000 Message-ID: <00a401c3f514$58244970$7502a8c0@hdsc.com> Reply-To: "Kumar" From: "Kumar" To: "sad" , References: <00f701c3f485$d7091430$7502a8c0@hdsc.com> <20040216054320.32df9226.Robert_Creager@LogicalChaos.org> <200402161623.24195.sad@bankir.ru> Subject: Re: Getting the week of a date Date: Tue, 17 Feb 2004 10:40:19 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/204 X-Sequence-Number: 16894 Seems a part of your function always returns '0' select 1 - (to_char(date_trunc('month',now()),'D'))::INT2 because while we use date_trunc it will always return the first day of the month and when it get subtracted by '1' it be always zero. Is there any reason why you have included that? Thanks Kumar ----- Original Message ----- From: "sad" To: Sent: Monday, February 16, 2004 6:53 PM Subject: Re: [SQL] Getting the week of a date EXCUSE ME, GUYS ! i forgot to add one monome: 7*(((to_char(date_trunc('month',now()),'D'))::INT2-1)/4) which is stands for skip a first week of month in case it is not consist Wed finally the select will be similar the following SELECT 7*(((to_char(date_trunc('month',now()),'D'))::INT2-1)/4) + 1 - (to_char(date_trunc('month',now()),'D'))::INT2 + 7*3-3 ; 4 - is a number of Wed in a week (in postgresql numeration) ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly