From: | "Josh Berkus" <josh(at)agliodbs(dot)com> |
---|---|
To: | "pauLSiew" <paul(at)mqplayharder(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Date Problem |
Date: | 2002-02-22 16:51:55 |
Message-ID: | web-700688@davinci.ethosmedia.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Samuel J. Sutjiono | 2002-02-22 17:04:38 | Regular Expression for 'and' instead of 'or' |
Previous Message | Roberto Mello | 2002-02-22 16:28:56 | Re: quotes nightmare! |