DateName function in SQL generally returns the string equivalent part of the date.
It generally takes two arguments, first part being the part of the date we want and the second refers to the date from which the part is to be extracted.
Example # 1:
Suppose if I want the month part of the date 23/06/2014
Example # 2:
Suppose lets say I want the Weekday part of the date 18th Oct 1987, 11:30 AM
(As a matter of fact its the exact time and date of my birth 🙂 )
Alternatively, we can also abbreviate the DateName notation:
DateName(Month,’2016-01-01′) can also be written as DateName(mm,’2016-01-01′).
A complete list of abbreviations is given below:
|Day of Year||dy||y|
A sample use of DateName function:
The DateName function can also be applied across Non-Deterministic functions such as GetDate().