This query gets node created dates and selects all years of nodes that has been made. Also there are filters: node.status equals 1 is published filter, node.type is content type filter and node language is language filter which I have set to current language.
Source code viewer
global $language; $result = db_query("SELECT EXTRACT(YEAR FROM((DATE_ADD('19700101', INTERVAL node.created SECOND) + INTERVAL 10800 SECOND))) AS created_year, COUNT(node.nid) AS num_records FROM {node} node WHERE (( (node.status = '1') AND (node.type IN ('article')) AND (node.language IN (:lang)) )) GROUP BY created_year ORDER BY created_year DESC", array(':lang' => $language->language)); if ($result->rowCount() > 0) { foreach($result as $row) { echo $row->created_year; } }Programming Language: PHP