Русский    English

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

  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.

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

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

Suggested exercises: 110

Bookmark and Share
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 CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema date/time functions DATEADD DATEDIFF DATENAME DATEPART DATETIME DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates EXCEPT exercise (-2) exercise 19 exercise 23 exercise 32 More tags
The book was updated
several days ago
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.
Rambler's Top100