There are times when you want to count objects by month or year for a date attribute. The following DQL shows how to count objects of type dm_document by the month of their creation using the DATETOSTRING function.
select DATETOSTRING(r_creation_date, 'yy/mm') as period, count(*)
group by DATETOSTRING(r_creation_date, 'yy/mm')
You can add a where clause as usual if you want to add conditions to the query. You can also play with the date format but know that some format strings may not work as you might expect them to.