loading..
Русский    English
14:54

DATENAME function

The function DATENAME ( datepart , date ) returns a character string representing the specified datepart of the specified date. An argument representing the datepart can be one of the values listed in above table.

The function gives us a simple opportunity to concatenate the date components to get any required format. For example, the query

Console
Execute
  1. SELECT DATENAME(weekday, '20031231' )+', ' + DATENAME(day, '20031231') +
  2. ' ' + DATENAME(month, '20031231') + ' ' + DATENAME(year,'20031231');
gives the following result:

Wednesday, 31 December 2003

Notice that DATENAME function reveals the difference between day and dayofyear values of the datepart argument. The first gives a character representation of the day of the specified date, whereas the second gives a character representation of this day from the origin of a year, i.e.

Console
Execute
  1. SELECT DATENAME(day, '20031231');
gives 31, but

Console
Execute
  1. SELECT DATENAME(dayofyear, '20031231');
results in 365.

Suggested exercises: 110

Bookmark and Share
Tags
aggregate functions Airport ALL AND AS keyword ASCII AVG Battles Bezhaev Bismarck C.J.Date calculated columns Cartesian product CASE cast CHAR CHARINDEX Chebykin check constraint classes COALESCE common table expressions comparison predicates Computer firm CONSTRAINT CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema DATEADD DATEDIFF DATENAME DATEPART DATETIME date_time functions DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates edge equi-join EXCEPT exercise (-2) More tags
The book was updated
month ago
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.