MySQL: DAYOFWEEK Function

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

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

Description

The MySQL DAYOFWEEK function returns the weekday index for a date value.

Syntax

The syntax for the DAYOFWEEK function in MySQL is:

DAYOFWEEK( date_value )

Parameters or Arguments

date_value

The date or datetime value from which to extract the day of the week.

Note

  • The DAYOFWEEK function returns the weekday index where 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday.

Applies To

The DAYOFWEEK 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 DAYOFWEEK function examples and explore how to use the DAYOFWEEK function.

For example:

mysql> SELECT DAYOFWEEK('2014-01-27');
Result: 2

mysql> SELECT DAYOFWEEK('2014-01-28');
Result: 3

mysql> SELECT DAYOFWEEK('2014-01-29');
Result: 4

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

mysql> SELECT DAYOFWEEK(CURDATE());

Next Topic : Click Here

This Post Has One Comment

Leave a Reply