Datepart function in SQL Server 2008
In this article I describe about DATEPART() function in SQL.
Introduction
DATEPART() Function is used to retreive only a part of date or time from the datetime variable. Let us take practical example to implement DATEPART function.
Syntax
where,
datepart- denotes which part is to be returned. It can be date, month or year.
Example
SELECT DATEPART(year, '12-07-1988') AS 'Year'
SELECT DATEPART(year, GETDATE()) AS 'Year'
SELECT DATEPART(month, GETDATE()) AS 'Month'
SELECT DATEPART(hour, GETDATE()) AS 'Hour'
Output: