Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
vchris
Forum Contributor
Posts: 204 Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec
Post
by vchris » Tue Sep 20, 2005 6:03 pm
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.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Tue Sep 20, 2005 6:24 pm
ryanlwh
Forum Commoner
Posts: 84 Joined: Wed Sep 14, 2005 1:29 pm
Post
by ryanlwh » Tue Sep 20, 2005 6:25 pm
$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 » Tue Sep 20, 2005 6:50 pm
Got it resolved with DATE_FORMAT().
Thanks