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. Link to comment https://forums.phpfreaks.com/topic/3092-display-information-where-field-has-yyyy-in-it/ 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. Link to comment https://forums.phpfreaks.com/topic/3092-display-information-where-field-has-yyyy-in-it/#findComment-10357 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? Link to comment https://forums.phpfreaks.com/topic/3092-display-information-where-field-has-yyyy-in-it/#findComment-10359 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. Link to comment https://forums.phpfreaks.com/topic/3092-display-information-where-field-has-yyyy-in-it/#findComment-10363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.