w3resource

MySQL DAYOFWEEK() function

DAYOFWEEK() function

MySQL DAYOFWEEK() returns the week day number (1 for Sunday,2 for Monday …… 7 for Saturday ) for a date specified as argument.

This function is useful in -

  • DAYOFWEEK() is used to categorize, analyze, and visualize data based on the day of the week.
  • It's useful for identifying patterns, trends, or variations that occur on specific days.
  • By using DAYOFWEEK(), you can obtain numeric values that represent days, which can be translated into day names for labeling or presentation purposes.
  • DAYOFWEEK() is valuable for analyzing business operations that vary by day of the week, such as customer behavior, sales, or website traffic.
  • In queries that involve filtering data based on specific days, DAYOFWEEK() helps categorize days and allows accurate filtering.
  • DAYOFWEEK() aids in optimizing schedules and operations that vary by day of the week, such as planning promotions or adjusting staff shifts.
  • When aligning dates with day-specific activities, DAYOFWEEK() ensures accurate alignment with the appropriate days.

Syntax:

DAYOFWEEK(date)

Where date is a date.

Syntax Diagram:

MySQL DAYOFWEEK() Function - Syntax Diagram

MySQL Version: 8.0

Pictorial Presentation:

Pictorial Presentation of MySQL DAYOFWEEK() function

Example: MySQL DAYOFWEEK() function

The following statement will return the week day number of the specified date 2008-05-15.

Code:

SELECT DAYOFWEEK('2008-05-15');

Output:

mysql> SELECT DAYOFWEEK('2008-05-15');
+-------------------------+
| DAYOFWEEK('2008-05-15') |
+-------------------------+
|                       5 | 
+-------------------------+
1 row in set (0.00 sec)

Video Presentation:

All Date and Time Functions:

Click here to see the MySQL Date and time functions.

Previous: DAY OF MONTH()
Next: DAY OF YEAR()



Follow us on Facebook and Twitter for latest update.