T-SQL Tutorial

DATENAME Date Function


Datename is an date function and returns a character string that represents the specified date_part(year, month or day) of the specified date.

DATENAME Syntax:

DATENAME (datepart, date)

DATENAME Example:

SELECT DATENAME(year,'2014-02-22 08:23:49.1234567 +05:10') as Year,
DATENAME(month,'2014-02-22 08:23:49.1234567 +05:10') as Month,
DATENAME(day,'2014-02-22 08:23:49.1234567 +05:10') as Day,
DATENAME(dayofyear,'2014-02-22 08:23:49.1234567 +05:10') as Dayofyear,
DATENAME(week,'2014-02-22 08:23:49.1234567 +05:10') as Week,
DATENAME(weekday,'2014-02-22 08:23:49.1234567 +05:10') as Weekday,
DATENAME(quarter,'2014-02-22 08:23:49.1234567 +05:10') as Quarter;

YearMonthDayDayofyearWeekWeekdayQuarter
2014February22538Saturday1

SELECT DATENAME(hour,'2014-02-22 08:23:49.1234567 +05:10') as Hour,
DATENAME(minute,'2014-02-22 08:23:49.1234567 +05:10') as Minute,
DATENAME(second,'2014-02-22 08:23:49.1234567 +05:10') as Second,
DATENAME(millisecond,'2014-02-22 08:23:49.1234567 +05:10') as Millisecond,
DATENAME(microsecond,'2014-02-22 08:23:49.1234567 +05:10') as Microsecond,
DATENAME(nanosecond,'2014-02-22 08:23:49.1234567 +05:10') as Nanosecond;

HourMinuteSecondMillisecondMicrosecondNanosecond
82349123123456123456700