Updated on 2026-11-06 GMT+08:00

weekday

The weekday function is used to return the day of the week for the date value (Monday is 0).

Syntax

weekday (string date)

Parameters

Table 1 Parameter description

Parameter

Mandatory

Type

Description

date

Yes

DATE or STRING

The date to be processed.

Formats:
  • yyyy-mm-dd
  • yyyy-mm-dd hh:mi:ss
  • yyyy-mm-dd hh:mi:ss.ff3

Return Values

Returns a value of type INT.

  • Monday is considered the first day of the week and returns 0. Other days increment sequentially, and Sunday returns 6.
  • If date is not of type DATE or STRING, an error is returned with the message "data type mismatch".
  • If date is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
  • If the date value is NULL, NULL is returned.

Example Code

Returns 2.

select weekday ('2023-08-16 10:54:36');

Returns NULL.

select weekday (null);