loading..
Русский    English
02:19

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
The book was updated
yesterday
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.
Rambler's Top100