Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Dealing with dates
Working with time data
Date and time date
Extracting dates and times
26. The DATENAME() function
Doing arithmetic with dates
Converting date and time data
Building date and time data from parts
Summary and review


Good. Let's look at a similar function, DATENAME:

  DATENAME(datepart, date)

As you see, it takes the same parameters as DATEPART. The datepart value can be any of the units we already discussed, and the date can be a string, a field, or an expression. The difference is that it returns the result as a string rather than an integer. If, for example, the month value was 05, DATENAME would return 'May' instead of 5.

Look at this example:

  DATENAME(year, Date) AS Year,
  DATENAME(month, Date) AS Month,
  AVG(Delay) AS AvgDelay
FROM Flight
  DATENAME(month, Date);

This query returns three columns: one with the year, the second with month (by name), and the third with the average delay.


For each discontinued aircraft, show its Id and the day of the week (by name) when it was discontinued. Name the column Weekday. Use DATENAME(weekday, date).

Stuck? Here's a hint!

Remember that all the discontinued aircraft don't have NULL in the DiscontinuationDatetime column.