MySQL – WEEKDAY() Function Examples

MySQL – WEEKDAY() Function Examples

In this MySQL tutorial, you will learn MySQL WEEKDAY() function. We will provide many examples of MySQL WEEKDAY() with its syntax.

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.

You may like

  1. LAST_DAY MySQL Function Examples
  2. MySQL CURRENT TIMESTAMP Function Examples
  3. Get month name from date in mysql
  4. mysql get first day of the current month
  5. mysql last day of previous month
  6. Get month number from month name in mysql
  7. mysql get day of week number from date
  8. Mysql Get Data Of Current Date, Week, Month, YEAR
  9. Query For Get Data Of Last Day, Week, Month, YEAR – Mysql

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


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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