DatabaseMySQL Quick Tip: Using the DAYOFWEEK Function

MySQL Quick Tip: Using the DAYOFWEEK Function

MySQL Database Tutorials

Knowing the day of the week for a provided date is a frequent requirement for programs and database admins looking to cull data from a database. Fortunately, MySQL has a function, known as DAYOFWEEK that makes gathering this information simple.

The order of days begins with Sunday (1), Monday (2), Tuesday (3), Wednesday (4), Thursday (5), Friday (6), and end on Saturday (7).

You can use the SELECT command with the DAYOFTHEWEEK function to query the MySQL database to find which day of the week a specific date falls on. For instance, here is an example MySQL query using DAYOFWEEK:

SELECT DAYOFWEEK('2021-03-11');

Running this query would result in the output:

5

As November 3rd, 2021 falls on a Thursday, which is the 5th day of the week.

Read: MySQL INSERT or REPLACE Commands

Latest Posts

Related Stories