MySQL: WEEKDAY Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL WEEKDAY Function

In this guide, we will explain how to use the MySQL WEEKDAY function with syntax and examples.

Description

The MySQL WEEKDAY function returns the weekday index for a date.

Syntax

The syntax for the WEEKDAY function in MySQL is:

WEEKDAY( date_value )

Parameters or Arguments

date_value

A date or datetime value from which to extract the weekday index.

Note

  • The WEEKDAY function returns the index of the weekday (0=Monday, 1=Tuesday, 2=Wednesday, 3=Thursday, 4=Friday, 5=Saturday, 6=Sunday) given a date value.
  • See also the DAYNAME function.

Applies To

The WEEKDAY function can be used in the following versions :

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some WEEKDAY function examples and explore how to use the WEEKDAY function.

For example:

mysql> SELECT WEEKDAY('2014-01-27');
Result: 0

mysql> SELECT WEEKDAY('2014-01-28');
Result: 1

mysql> SELECT WEEKDAY('2014-01-29 08:35:17');
Result: 2

This last WEEKDAY example would display the weekday index for the current system date (current system date is returned by the CURDATE function).

mysql> SELECT WEEKDAY(CURDATE());

Next Topic : Click Here

This Post Has One Comment

Leave a Reply