DBookatay Posted November 2, 2010 Share Posted November 2, 2010 SELECT * FROM Sold WHERE substr(sold_date, 0, 4) = 2010 What I am trying to do is select all rows from the database from 2010, from the "sold_date" field. How is this accomplished with date values? (ex: "2010-08-11", "2009-01-15") Quote Link to comment https://forums.phpfreaks.com/topic/217597-help-with-a-simple-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 What you posted should work. However YEAR() would be clearer and probably faster - SELECT * FROM Sold WHERE YEAR(sold_date) = 2010 Quote Link to comment https://forums.phpfreaks.com/topic/217597-help-with-a-simple-query/#findComment-1129672 Share on other sites More sharing options...
DBookatay Posted November 2, 2010 Author Share Posted November 2, 2010 What you posted should work. However YEAR() would be clearer and probably faster - SELECT * FROM Sold WHERE YEAR(sold_date) = 2010 My code didn't work, yours did though. Thank you... Quote Link to comment https://forums.phpfreaks.com/topic/217597-help-with-a-simple-query/#findComment-1129675 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 Upon further review, the first position for substr() is 1. Quote Link to comment https://forums.phpfreaks.com/topic/217597-help-with-a-simple-query/#findComment-1129679 Share on other sites More sharing options...
DBookatay Posted November 2, 2010 Author Share Posted November 2, 2010 Upon further review, the first position for substr() is 1. I'm sorry but I don't understand Quote Link to comment https://forums.phpfreaks.com/topic/217597-help-with-a-simple-query/#findComment-1129683 Share on other sites More sharing options...
PFMaBiSmAd Posted November 2, 2010 Share Posted November 2, 2010 Should work (however as mentioned, the year() function is probably a lot faster) - SELECT * FROM Sold WHERE substr(sold_date, 1, 4) = 2010 Quote Link to comment https://forums.phpfreaks.com/topic/217597-help-with-a-simple-query/#findComment-1129686 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.