Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 2AB36475D26 for ; Fri, 22 Feb 2002 11:51:52 -0500 (EST) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.2) with HTTP id 700688; Fri, 22 Feb 2002 08:51:55 -0800 From: "Josh Berkus" Subject: Re: Date Problem To: "pauLSiew" , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.5.2 Date: Fri, 22 Feb 2002 08:51:55 -0800 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200202/318 X-Sequence-Number: 6740 Paul, > I'm using pgsql with php, and my query below will retrieve employee's > monthly sales total, > > "select sum(salesTotal) from ocf where employeeNo='0123' AND > orderDate like > '%$month $year %'" // i put % infront to ignore day, and % at the > back to > ignore the time (because i'm using timestamp with timezone), then i > shall > get particular month's records. The main problem is that you are treating the TIMESTAMP field like it is text. It is not. You cannot use comparitors designed for text parsing (such as "LIKE '%xxxyyy%') on TIMESTAMPs and get reliable results. Instead, use functions designed for TIMESTAMPs: http://www.postgresql.org/idocs/index.php?functions-datetime.html For example, you could: SELECT ... WHERE EXTRACT(month FROM orderdate) = $month AND EXTRACT(year FROM orderdate) = $year; ... but there are a few ways you can answer this question. Read the documentation page; better yet, buy and read a PostgreSQL book. -Josh Berkus P.S. In the future, questions of this type are more appropriate for the NOVICE list. The SQL list is more for the "how-do-I-get-this-insanely-complex-query-to-perform" type. ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco