MySQL WEEKDAY() Function Examples

MySQL WEEKDAY() Function Examples

MySQL WEEKDAY() function; Through this tutorial, we will learn MySQL WEEKDAY() function. We will provide many examples of MySQL WEEKDAY() with its syntax.

And as well as, we will also explain the difference between Mysql WEEKDAY() vs DAYOFWEEK() with example.

MySQL WEEKDAY() Function

In MySQL, WEEKDAY function is used to returns the weekday index for a date. Just provide the date as a argument(params) and the it will return the weekday index.


The WEEKDAY() function syntax is:


Here date is the date value that you want return the weekday name from.


Now we take different different type of examples of WEEKDAY function. See below all the examples one by one.


First simple example to demonstrate.

SELECT WEEKDAY('2019-07-11') AS 'Result';


 | Result  |
 |    3    |

Example-2 With Database Queries

For some time we want to fetch a record / data from the mysql database table. When we need to get the week day of a table in the database. In that case we use WEEKDAY() with mysql queries.

Next, we take example-2, in this example we will fetch WEEKDAY of database table name users where column name is created_at.

 created_at AS create_date,
 WEEKDAY(created_at) AS week_day
 FROM users
 WHERE id = 1;


 | create_date         | week_day     |
 | 2019-07-11 11:30:37 |        3     |

Example-3 of WEEKDAY() vs DAYOFWEEK()

In example-3, we take an example to differentiate weekday() and dayofweek() function.

 SET @date = '2019-07-13';
   DAYOFWEEK(@date) AS 'Day OF WEEK',
   WEEKDAY(@date) AS 'Weekday';
MySQL WEEKDAY() function returns the weekday number for a given date(between 0 to 6).MySQL DAYOFWEEK() function returns the weekday index for a given date (between 1 to 7).
1 to 7 means:
1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday.
0 to 6 means:
0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday.


| Day Of Name | Weekday     |
| 7           |       5     |

Example-4 Using Current Date/Time

Now we take new example using current date with WEEKDAY() function. It will return weekday from the current date & time.



 | NOW()               | WEEKDAY(NOW()) |
 | 2018-07-13 10:05:41 |   5            |

Example-5 Using MySQL CURDATE() Function

Next, we will take another example of WEEKDAY() with CURDATE() function. Which is returns only the weekday.



 | 2019-07-13 |     5              |

Example-6 with DAYNAME() Function

We will take a comparison example to simplify our example. Here we compare the WEEKDAY() and DAYNAME() functions which make our example easy.

Here, WEEKDAY function is used to returns the weekday index for a date. And DAYNAME gives the name of the date given as the string format.

 SET @date = '2020-01-25';
   DAYNAME(@date) AS 'Day Name',
   WEEKDAY(@date) AS 'Weekday';


| Day Name | Weekday |
| Saturday |       5 |


Here, You have learned how to use WEEKDAY() function with various examples.

Recommended MySQL Tutorials

If you have any questions or thoughts to share, use the comment form below to reach us.


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *