DATENAME

DATENAME is a built-in function in SQL Server that returns the specified part of a given date as a character string.

DATENAME( datepart , date )

  • datepart: This is the part of the date to return. It could be year, quarter, month, day of the year, day, week, weekday, hour, minute, second, millisecond, microsecond, nanosecond. The part specified will determine what aspect of the date value will be extracted.
  • date: This refers to the actual date value from which you want to extract the part specified by datepart. It can be a date, time, date time2, datetimeoffset, smalldatetime, datetime, or string literal.

Example

SELECT DATENAME(month, GETDATE()) AS 'Month'

Output

"October"

Explanation

In the above SQL query, the DATENAME() function is used to extract the name of the month from the current date (GETDATE()). The result is the English name of the current month, “October”.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.