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 Link to comment https://forums.phpfreaks.com/topic/232200-timestamps-bit-of-a-newbie-question/ 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 Link to comment https://forums.phpfreaks.com/topic/232200-timestamps-bit-of-a-newbie-question/#findComment-1194464 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')"); ?? Link to comment https://forums.phpfreaks.com/topic/232200-timestamps-bit-of-a-newbie-question/#findComment-1194472 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 Link to comment https://forums.phpfreaks.com/topic/232200-timestamps-bit-of-a-newbie-question/#findComment-1194477 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' Link to comment https://forums.phpfreaks.com/topic/232200-timestamps-bit-of-a-newbie-question/#findComment-1194479 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 Link to comment https://forums.phpfreaks.com/topic/232200-timestamps-bit-of-a-newbie-question/#findComment-1194483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.