SQL Group By Date

There are time when you want to group query result by date. Be that year month or day. The below group by clauses will achieve this for you.

Sql group by day:


GROUP BY	DATEADD(DAY,0, DATEDIFF(DAY,0, CreatedOn))

Sql group by month:


GROUP BY	DATEADD(MONTH,0, DATEDIFF(MONTH,0, CreatedOn))

Sql group by year:


GROUP BY	DATEADD(YEAR,0, DATEDIFF(YEAR,0, CreatedOn))