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;
Year | Month | Day | Dayofyear | Week | Weekday | Quarter |
---|---|---|---|---|---|---|
2014 | February | 22 | 53 | 8 | Saturday | 1 |
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;
Hour | Minute | Second | Millisecond | Microsecond | Nanosecond |
---|---|---|---|---|---|
8 | 23 | 49 | 123 | 123456 | 123456700 |