Orionsbelter Posted March 30, 2011 Share Posted March 30, 2011 Ok sorry if this is a proper newbie question but say i have a timestamp saved in a database in a table called "news" and the field is called "date" how do i get the month and year only from example if the time stamp is 2011-03-29 13:57:05. And i want to list all news articles from the month 03 and the year 2011 how would i go about doing this? Thank you for reading Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 30, 2011 Share Posted March 30, 2011 Assuming MySQL, maybe use the MONTH() and YEAR() functions in your query? http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html Quote Link to comment Share on other sites More sharing options...
Orionsbelter Posted March 30, 2011 Author Share Posted March 30, 2011 So like mysql_query("SELECT * FROM `news` WHERE date= MONTH('03')"); ?? Quote Link to comment Share on other sites More sharing options...
Orionsbelter Posted March 30, 2011 Author Share Posted March 30, 2011 tried that $num=mysql_num_rows(mysql_query("SELECT * FROM `news` WHERE Date MONTH('03') AND Date YEAR('2011')")); got no luck Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted March 30, 2011 Share Posted March 30, 2011 Read the manual for the MONTH() and YEAR(): SELECT * FROM `news` WHERE MONTH(`Date`) = '03' AND YEAR(`Date`) = '2011' Quote Link to comment Share on other sites More sharing options...
Orionsbelter Posted March 30, 2011 Author Share Posted March 30, 2011 Thank you will try it and give it a read 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.