Function Reference

DAYOFWEEK

PostgreSQL equivalent:

Returns the weekday number of a date, counting from Sunday.

MySQL 8.1
DAYOFWEEK(date)

Parameters

dateDATE
Date or datetime

Return value

An integer from 1 to 7, where 1 is Sunday and 7 is Saturday; NULL for an incomplete date (2022-00-00) and for an unrecognized value

Examples

Weekday number

MySQL 8.1
SELECT DAYOFWEEK('2022-06-16');
DAYOFWEEK('2022-06-16')
5

Payments on weekends

MySQL 8.1
SELECT payment_id,
	date,
	DAYOFWEEK(date) AS weekday_number
FROM Payments
WHERE DAYOFWEEK(date) IN (1, 7);
payment_iddateweekday_number
12005-02-127
32005-05-147
62005-02-201
72005-07-307
142005-10-231
202005-06-117
222006-03-121
232005-06-051
282006-01-151

Details

To number the days from Monday (1 is Monday, 7 is Sunday), use WEEKDAY(date) + 1.

See also