Cloud Training (Online)




SQL Server 101 – GROUP BY datetime and ignore time

Assume that you have a Order table and you want to query the table to retreive the total orders made each day. You can do this by using the GROUP BY with the Datetime fields being type casted to date as shown below.

How to Group By datetime and ignore time in SQL Server ?

SELECT CAST(OrderDateTime AS DATE) as OrderDate, COUNT(1) as TotalOrders
FROM Orders
GROUP BY CAST(OrderDateTime AS DATE)