All Products
Search
Document Center

MaxCompute:DAYOFWEEK

Last Updated:Jul 24, 2023

Returns the day of the week in which a date value falls.

Syntax

int dayofweek(datetime|timestamp|date|string <date>)

Parameters

date: required. A date value of the DATETIME, TIMESTAMP, DATE, or STRING type. The input value is in the yyyy-mm-dd, yyyy-mm-dd hh:mi:ss, or yyyy-mm-dd hh:mi:ss.ff3 format. If the value is of the STRING type, the value must include at least the yyyy-mm-dd part and must not contain extra strings.

Return value

A value of the INT type is returned. The return value varies based on the following rules:

  • If the value of date is not of the DATETIME, TIMESTAMP, DATE, or STRING type or the format does not meet the requirements, null is returned.

  • If the value of date is null, null is returned.

  • The return value ranges from 1 to 7. The value 1 indicates Sunday, the value 2 indicates Monday, and the same rule applies to other values.

Examples

-- The value 5, which indicates Thursday, is returned. 
SELECT dayofweek('2009-07-30');

Related functions

DAYOFWEEK is a date function. For more information about functions related to date computing and conversion, see Date functions.