Jump to content

Archived

This topic is now archived and is closed to further replies.

tjhilder

display information where field has 'YYYY' in it

Recommended Posts

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.

Share this post


Link to post
Share on other sites

Yes -- use the YEAR() function:

 

$view_2005 = "SELECT * FROM gallery WHERE YEAR(date_sort)='2005' ORDER BY date_sort DESC";

 

Hope that helps.

Share this post


Link to post
Share on other sites

[!--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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.