I have a variable that a user specifies $start_date in format of y-m-d.
so let’s say for example $start_date = '2011-10-27';
In my database I have a DATETIME field, let’s call it sample_date that looks like this
2011-10-27 14:15:20
When I run sql query using $start_date.. do I have to convert to compare the dates such as
SELECT * from content WHERE sample_date >= $start_date
or should I convert it somehow first
You don’t need to convert the value as long as you’ve validated the format, but you should definitely sanitize the input to prevent XSS attacks and other nastiness. A calendar drop-down would be good here as well.
EDIT:
Whoa now… I see you’ve edited your question and the formats are different. That changes everything! Michael’s comment is the correct answer, use strtotime() function to convert the date to a unix timestamp, then recreate the date in the proper format needed… like so… date(‘Y-m-d’, strtotime($start_date))