Skip to main content

TO_START_OF_WEEK

Returns the first day of the week for a date or a date with time (timestamp/datetime). The first day of a week can be Sunday or Monday, which is specified by the argument mode.

Syntax

to_start_of_week(expr[, mode])

Arguments

ArgumentsDescription
exprdate/timestamp
modeOptional. If it is 0, the result is Sunday, otherwise, the result is Monday. The default value is 0

Return Type

Datetime object, returns date in “YYYY-MM-DD” format.

Examples

SELECT to_start_of_week(now());
+-------------------------+
| to_start_of_week(now()) |
+-------------------------+
| 2022-03-27 |
+-------------------------+

SELECT to_start_of_week(to_timestamp(1630812366));
+--------------------------------------------+
| to_start_of_week(to_timestamp(1630812366)) |
+--------------------------------------------+
| 2021-09-05 |
+--------------------------------------------+

SELECT to_start_of_week(to_timestamp(1630812366), 1);
+-----------------------------------------------+
| to_start_of_week(to_timestamp(1630812366), 1) |
+-----------------------------------------------+
| 2021-08-30 |
+-----------------------------------------------+