Page 1 of 1

compare months

Posted: Tue Sep 20, 2005 6:03 pm
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.

Posted: Tue Sep 20, 2005 6:24 pm
by hawleyjr

Posted: Tue Sep 20, 2005 6:25 pm
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";

Posted: Tue Sep 20, 2005 6:50 pm
by vchris
Got it resolved with DATE_FORMAT().

Thanks