RSS Feed

DATENAME Function Examples

DATENAME Function Examples


This DATENAME() function returns a character string that represents a part of a given date and time value. Lets see some of the examples of DATENAME() function.

DATENAME Example 1
Below queries find today's day. Result of both the queries is same:

SELECT DATENAME(dw, getdate()) AS 'Today Is'
SELECT DATENAME(weekday, getdate()) AS 'Today Is'

Result:
Today Is
Monday

DATENAME Example 2
Below queries find current week. Result of all the 3 queries is same:

SELECT DATENAME(week, getdate()) AS 'This is week'
SELECT DATENAME(wk, getdate()) AS 'This is week'
SELECT DATENAME(ww, getdate()) AS 'This is week'

Result:
This is week
30

DATENAME Example 3
Below queries find current month. Result of all the 3 queries is same:

SELECT DATENAME(month, getdate()) AS 'This is month'
SELECT DATENAME(mm, getdate()) AS 'This is month'
SELECT DATENAME(m, getdate()) AS 'This is month'

Result:
This is month
July

DATENAME Example 4
Below queries find current quarter. Result of all the 3 queries is same:

SELECT DATENAME(quarter, getdate()) AS 'This is quarter'
SELECT DATENAME(q, getdate()) AS 'This is quarter'
SELECT DATENAME(qq, getdate()) AS 'This is quarter'

Result:
This is quarter
3

DATENAME Example 5
Below queries find current year. Result of all the 3 queries is same:

SELECT DATENAME(year, getdate()) AS 'This is year'
SELECT DATENAME(yyyy, getdate()) AS 'This is year'
SELECT DATENAME(yy, getdate()) AS 'This is year'

Result:
This is year
2017

DATENAME Example 6
Below query finds current timezone.

Select DATENAME(tz,SYSDATETIMEOFFSET())

Result:
(No column name)
+05:30