Re: Date problem

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Date problem
Date: 2002-02-23 02:19:54
Message-ID: slrna7duu4.6j.missive@whave.frontiernet.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>> > "select sum(salesTotal) from ocf where employeeNo='0123' AND orderDate
> like
>> > '%$month $year %'" // i put % infront to ignore day, and % at the back
> to
>>
>> How about
>> ... like '%$month-$year%' ...
>>

>> > $month = Feb
>> > $year = 2002
>> >
>> > But i cant retrieve the data, if i take out the $year, it works...but i
>> > need the year to identify the records.
>> >
>> > it works when i do a direct sql query to the pgsql through pg-admin, the
>> > query are like this,
>> > select grand_total,ocf_no,date from ocf where date like '2002-01%' order
> by
>>
>> Here, you have the dash between month and year ................^
>> You also have year and month reversed from above... Could be trouble!
>>
> it works when i put '%$month%', but this will only retrieve the month, but
> any year, cause year din't specified, so i put the $year in like the 1st
> query above, it's did not work, then i try all the possible, it dont work
> also :(
>

LIKE matches strings, so
LIKE 'aaa%bbb'
would match
aaafdsglkjfdgldsjgbbb
aaabbb
aaa12345678bbb
aaaetcbbb

so if you want to match date strings which look like
...2001-01...
...2001-11...
...2002-03...
...2002-10...

you will need to use
LIKE '%2001-01%'
LIKE '%2001-11%'
LIKE '%2002-03%'
LIKE '%2002-10%'

How you get PHP to make strings like that is left as
an exercise!

HINT: You can crank up the PostgreSQL logging to show
the queries which are actually being run.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Lacey 2002-02-23 03:02:19 Re: ANY GOOD USER'S GUIDE ONLINE?? (with simple examples)
Previous Message Konrad Scherer 2002-02-23 02:07:53 Wierdness using SUM to add results of custom C function.