DATEPART function is used in Microsoft SQL Server to return a single part of a date/time, such as year, month, day, etc.
In this example, we want to find out what is the employees’ year of hire.
DATEPART Reference Table
SELECT employeeName as [Employee Name], DATEPART(year,hireDate) as [Year Hired] FROM employees
|Employee Name||Year Hired|
DATEPART function can be very useful when you are interested in formatting the results using a specific format of a date and/or time.