Pages

Men

rh

7/17/2012

DATE PART FUNCTIONS in SQL Server

DATE PART FUNCTIONS

This is used, when we need a part of date or time from a date time variable. 

We can use DATEPART() method only with select command.

Example:

SELECT DATEPART(year, GETDATE()) AS 'Year'
Output:
Year
2012

SELECT DATEPART(month, GETDATE()) AS 'Month'
Output:
Month
7

SELECT DATEPART(hour, GETDATE()) AS 'Hour'

Output:
Hour
15



Back

No comments :

Post a Comment