Use extract(month from the_date) instead of to_char. See datetime functions in the Pg docs.
With to_char you'll suffer from all sorts of issues with case, localisation, and more.
Assuming you meant that the data type of effective_date was timestamp or date, you'd write:
$query = "select *
from ". $this->getTable() ."
where pay_stub_entry_name_id = 43
AND extract(month from effective_date) = 7
AND deleted = 0";
If it's integer then - assuming it's an epoch date - you have to convert it to a timestamp with to_timestamp, then use extract on it. See the epoch section in the documentation linked to above, eg:
$query = "select *
from ". $this->getTable() ."
where pay_stub_entry_name_id = 43
AND extract(month from to_timestamp(effective_date)) = 7
AND deleted = 0";
The immediate cause of your problem was that you were calling to_char(integer,text) with an integer epoch date. Only the timestamp versions of to_char do date formatting; Mon isn't special for the others, so it was simply output as a literal string Mon. Compare:
regress=# SELECT to_char(current_timestamp, 'Mon');
to_char
---------
Aug
(1 row)
regress=# select to_char( extract(epoch from current_timestamp), 'Mon');
to_char
---------
Mon
(1 row)
Remember to parameterise your real-world versions of these queries to help avoid SQL injection.
effective_datehas data typeinteger? Notdate? Nottimestamp? Was that a mistake in your question? If it's an integer how do you expect to get a date out of it? Is it an epoch date (seconds since a certain date)?to_chardo? Did you try it inpsql? Let's see:select to_char( extract(epoch from current_timestamp), 'Mon')just outputs the stringMon, which will never equal the stringJul. So there's your problem, you were calling the integer version ofto_charand expecting it to just know you wanted to treat the integer as a date. See\df to_charin psql to see all theto_charvariants. Only thetimestampones work with date formatting as per the documentation