MSSQLDate/Time FunctionsDATEPART
DATENAME

DATEPARTDate/Time Functions

DAY

Returns the specified part of a date as an integer.

Syntax

DATEPART(unit, date)

Example

Enter values below to update the example in real time.

created_at
order_hour
cnt
orders
SELECT DATEPART(HOUR, created_at) AS order_hour, COUNT(*) AS cnt
FROM orders
GROUP BY DATEPART(HOUR, created_at);