DATENAME function
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
SELECT DATENAME(weekday, '20031231' )+', ' + DATENAME(day, '20031231') +
' ' + DATENAME(month, '20031231') + ' ' + DATENAME(year,'20031231');
🚫
[[ error ]]
[[ column ]] |
---|
[[ value ]] |
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.
SELECT DATENAME(day, '20031231');
🚫
[[ error ]]
[[ column ]] |
---|
[[ value ]] |
SELECT DATENAME(dayofyear, '20031231');
🚫
[[ error ]]
[[ column ]] |
---|
[[ value ]] |
Suggested exercises: 110