How to extract individual years from the date and time format (00-00-0000 00:00:00)? I am using Symfony 2 and DQL.
In SQL, it will be:
SELECT DISTINCT extract(year FROM created_at) FROM news ORDER BY created_at DESC
change
with SUBSTRING:
by years (date and time format Ymd H: i: s):
SELECT p, SUBSTRING(p.created_at, 1, 4) as year FROM news p GROUP BY year
source share