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") 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 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... 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. 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 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 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
Archived
This topic is now archived and is closed to further replies.