tjhilder Posted December 23, 2005 Share Posted December 23, 2005 I have a table called gallery and in that table is a field called date_sort, in that is information like YYYY-MM-DD. is it possible to have the query that looks like this.. $view_2005 = "SELECT * FROM gallery WHERE date_sort='2005' ORDER BY date_sort DESC"; changed so that it only displays the results that start with 2005-MM-DD ? how would I make this possible? thanks in advance. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 23, 2005 Share Posted December 23, 2005 Yes -- use the YEAR() function: $view_2005 = "SELECT * FROM gallery WHERE YEAR(date_sort)='2005' ORDER BY date_sort DESC"; Hope that helps. Quote Link to comment Share on other sites More sharing options...
tjhilder Posted December 23, 2005 Author Share Posted December 23, 2005 [!--quoteo(post=330075:date=Dec 23 2005, 11:36 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Dec 23 2005, 11:36 PM) 330075[/snapback][/div][div class=\'quotemain\'][!--quotec--] Yes -- use the YEAR() function: $view_2005 = "SELECT * FROM gallery WHERE YEAR(date_sort)='2005' ORDER BY date_sort DESC"; Hope that helps. wow thanks, that works great. how does YEAR() work exactly? Quote Link to comment Share on other sites More sharing options...
fenway Posted December 24, 2005 Share Posted December 24, 2005 Most of these are shortcut functions to the DATE_FORMAT() function, which allows you to retrieve just about any piece of the a date value that you can imagine. So, YEAR() is equivalent to calling DATE_FORMAT(date_field, '%Y'). Personally, I like to use the latter for flexibility and version back compatibility, but using YEAR() can make the code more readable. Quote Link to comment 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.