Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

sql
mysql
dayname
communitycreator

What is DAYNAME() in SQL?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The DAYNAME() function returns the weekday name when given a date sent as a parameter.

Figure 1 shows a visual representation of the DAYNAME() function.

Figure 1: Visual representation of DAYNAME() function

Syntax

DAYNAME(date)

Parameter

The DAYNAME() function takes the date as a parameter.

The date must be in the format YYYY-MM-DD, or else this function returns NULL.

Return value

The DAYNAME() function returns the weekday name from a date sent as a parameter.

This function returns NULL if the date is incorrect, i.e., the date is 0 or greater than 31.

Code

The following example shows how we can isolate the weekday name from the admission dates of students using the DAYNAME() function.

Students

Student ID

Student Name

Student Admission Date

1

David

2000-07-14

2

Luiss

2002-08-15

3

Harvey

2005-04-19

4

Lucy

2010-01-27

5

Andrew

2011-10-03

SELECT *, DAYNAME(studentAdmissionDate) as DayName
from Students;

RELATED TAGS

sql
mysql
dayname
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring