jim.davidson Posted August 11, 2010 Share Posted August 11, 2010 I'm trying to query a table that has a date field lableld created_sort. Here's the query SELECT needs_id, email_id, status, name, email FROM needs WHERE created_sort BETWEEN 2010-07-01 AND 2010-08-05 I know there are two records that fall between those dates but the query comes back empty. What's wrong with my query? Any help will be greatly appreciated. I've been fighting with this for hours. Quote Link to comment https://forums.phpfreaks.com/topic/210461-query-using-between-on-date-field-not-working/ Share on other sites More sharing options...
Mchl Posted August 11, 2010 Share Posted August 11, 2010 Put dates in quotes, otherwise MySQL will do the substraction (2010-07-01 = 2002) SELECT needs_id, email_id, status, name, email FROM needs WHERE created_sort BETWEEN '2010-07-01' AND '2010-08-05' Quote Link to comment https://forums.phpfreaks.com/topic/210461-query-using-between-on-date-field-not-working/#findComment-1098177 Share on other sites More sharing options...
jim.davidson Posted August 11, 2010 Author Share Posted August 11, 2010 Thank you very much! that's all it needed. Quote Link to comment https://forums.phpfreaks.com/topic/210461-query-using-between-on-date-field-not-working/#findComment-1098181 Share on other sites More sharing options...
Mchl Posted August 11, 2010 Share Posted August 11, 2010 Note: You can also use YYYYMMDD format without quotes. SELECT needs_id, email_id, status, name, email FROM needs WHERE created_sort BETWEEN 20100701 AND 20100805 Quote Link to comment https://forums.phpfreaks.com/topic/210461-query-using-between-on-date-field-not-working/#findComment-1098197 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.