Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

DAYOFWEEK

Example

Retrieve the index representing the weekday for a given date.

SELECT DAYOFWEEK(“2017-06-15”);

Definition and Usage

The DAYOFWEEK() function retrieves the weekday index for a specified date, represented as a number ranging from 1 to 7.

Note: 1 corresponds to Sunday, 2 to Monday, 3 to Tuesday, 4 to Wednesday, 5 to Thursday, 6 to Friday, and 7 to Saturday.

Syntax

DAYOFWEEK(date)

Parameter Values

Parameter

Description

date

Necessary. Specify the date from which to retrieve the weekday index.

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Retrieve the index representing the weekday for a given date.

SELECT DAYOFWEEK(“2017-06-15 09:34:21”);

Example

Retrieve the index representing the weekday for the current system date.

SELECT DAYOFWEEK(CURDATE());