I have a field of date-time type. I added this field into a view and formatted the date-time field to show only year. When I switch 'aggregation' on in Views and try to group this field it didn't work as i expect and show all the dates again. I saw the Vies-query and there wasn't any preformatting. It was grouping by dis field only. I want the modify the query to get this fields formatted as i need(years only). Any advices would be appreciated. Thanks in advance!

2 Answers 2


I don't think (I haven't seen your view) you need to enable aggregation to group by year. This is a solution:

  1. If you need to display the date field value add the field twice. You will use one for the display of the date and the other for the grouping by year. If you are not going to display the date, you still need the date field to be able to group by year.

  2. On the date field you are going to use to group by year you need a custom format that will only show you the year and if you are collecting both start and end date set it to you only the start date or the end date, but not both.

  3. To create a custom date format go to admin/config/regional/date-time in Drupal 7 or to admin/settings/date-time in Drupal 6. There you will create a date format that will only show the year and then create a date format type that will show that date format.

  4. Back to the date field you want to use to group by year change its format to the newly create format that only show you the date and set you show only one date and click apply. Also if you don't want the year value to show on the view check the option to exclude it.

  5. Depending on the view format you have chosen (Table, Unformatted list, HTML list, etc) you will click the setting of the format and you are going to set the date field with the newly date format as the grouping field. Click apply and you are done.

  6. You might also want to visit the "sort" section of your view to set the sort order of the dates.

  • Thanks for the answer but I need to use aggregation because i need the sum of a field after grouping the nodes by year :(. Anyway i tried your way but aggregation automatically adds group by to all fields(despite being excluded from display) and here comes my problem from the question again.
    – Martin
    Commented Sep 13, 2012 at 16:43

If you use aggregation in views you MUST remove all sort options or else it won't group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.