Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 8728E9FB69C for ; Mon, 23 Apr 2007 04:41:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 51151-10 for ; Mon, 23 Apr 2007 04:41:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id E2DC19FB235 for ; Mon, 23 Apr 2007 04:41:40 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l3N7fWva032954 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 23 Apr 2007 01:41:35 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id l3N7fVb9075552; Mon, 23 Apr 2007 01:41:32 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l3N7fV7f075551; Mon, 23 Apr 2007 01:41:31 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 23 Apr 2007 01:41:31 -0600 From: Michael Fuhr To: RPK Cc: pgsql-sql@postgresql.org Subject: Re: Retrieve month from date in SQl query Message-ID: <20070423074131.GA75312@winnie.fuhr.org> References: <10063035.post@talk.nabble.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <10063035.post@talk.nabble.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/213 X-Sequence-Number: 28213 On Wed, Apr 18, 2007 at 10:36:14AM -0700, RPK wrote: > I have a table called "StudentFeesPayment" with columns "ReceiptNo" and > "ReceiptMonthYear". > The column, "ReceiptMonthYear" stores date in the format "yyyy-mm-dd". I > have to find the max(ReceiptNo) where Month of (ReceiptMonthYear)=4. Or > whatever month I give. > > I tried: > > Select max(ReceiptNo) from StudentFeesPayment where > Extract(Month('ReceiptMonthYear'))=4; > > But it is not working. How to do it? Please explain how it's not working -- how does the result differ from your expectation? I'd guess you're getting a syntax error; see the documentation for the correct way to use extract(): http://www.postgresql.org/docs/8.2/interactive/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT -- Michael Fuhr