bulrush Posted May 21, 2010 Share Posted May 21, 2010 I would like to execute a SELECT statement where my field "mdate" (a DATE type field) is greater than or equal to the date the user entered, which is stored as a string in $startdate. I still don't understand how to compare DATE type fields. Is a DATE type field stored as a string, or stored as an integer and displayed automatically as a string in the YYYY-MM-DD format? Here is what I have that doens't work. $query = "SELECT mdate, miles, username, note, payrate, printdate ". "FROM mileage ". "WHERE (username='".$username."') ". "AND (mdate BEWEEN '$startdate' AND NOW()) ". "AND (printdate IS NULL) ". "ORDER BY mdate ". ";"; Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/202527-select-where-mdate-startdate/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2010 Share Posted May 21, 2010 As long as all the values have the correct (and same) format, the comparison will work. now() is a DATETIME value and you should not be comparing it with a DATE value. See CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/202527-select-where-mdate-startdate/#findComment-1061733 Share on other sites More sharing options...
Mchl Posted May 21, 2010 Share Posted May 21, 2010 now() is a DATETIME value and you should not be comparing it with a DATE value. Can lead to some tricky to find bugs. Quote Link to comment https://forums.phpfreaks.com/topic/202527-select-where-mdate-startdate/#findComment-1061770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.