compare months

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

compare months

Post by vchris »

Hi,

I am trying to compare a date/time column (sdate) to a variable "$requestmonth" which contains the month to be displayed.

Code: Select all

"SELECT * FROM schedule WHERE sdate = " . $requestmonth . " ORDER BY sdate";
This query doesn't work. No records are displayed.

How could I compare the months in sdate column to $requestmonth?




By the way it's in php.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

$requestmonth has to be in the exact format as sdate. date/time type is usually formatted as yyyy-mm-dd hh:mm:ss. you have to turn $requestmonth into that format. Also, you should add a single-quote around $requestmonth

Code: Select all

"SELECT * FROM schedule WHERE sdate = '" . $requestmonth . "' ORDER BY sdate";
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

Got it resolved with DATE_FORMAT().

Thanks
Post Reply