View Full Version : pulling out data from a db where the date field equals current yr?

10-13-2009, 02:01 PM

i am trying to pull out the news stories from a db where the dateSubmitted is equal to the current year, the problem is the dateSubmitted is stored as a date (2009-10-13) so how do i pullout the records where the year equals the current year?

here is my code

$currentYear = date('Y');
print $currentYear;
$getNews = "SELECT news_headline FROM news WHERE dateSubmitted = '$currentYear' ORDER BY dateSubmitted ASC";
$sql = mysql_query($getNews);
while($newsStories = mysql_fetch_array($sql))
print $newsStories['news_headline'];

nothing is printing out, so i assume that ive got to do something to the date which is stored in the db first to get this to work?


10-13-2009, 02:06 PM
WHERE YEAR(dateSubmitted) = '$currentYear'

or you don't even need any php code -

WHERE YEAR(dateSubmitted) = YEAR(CURDATE())

10-13-2009, 02:41 PM
Thanks mate!!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum