startofweek()

Learn how to use the startofweek() function to return the start of the week for the given date.

Returns the start of the week containing the date, shifted by an offset, if provided.

Start of the week is considered to be a Sunday.

Syntax

startofweek(date [, offset ])

Parameters

NameTypeRequiredDescription
datedatetime✔️The date for which to find the start of week.
offsetintThe number of weeks to offset from the input date. The default is 0.

Returns

A datetime representing the start of the week for the given date value, with the offset, if specified.

Examples

range offset from -1 to 1 step 1
| project weekStart = startofweek(datetime(2017-01-01 10:10:17), offset) 

Output

weekStart
2016-12-25 00:00:00.0000000
2017-01-01 00:00:00.0000000
2017-01-08 00:00:00.0000000

The following example returns the start of the week as Monday for the specified date.

let startofweekFromMonday = (dateArg: datetime) {
    datetime_add('day', 1, startofweek(datetime_add('day', -1, dateArg)))
};
let data=datatable(Date: datetime, day: string)
[
datetime(2025, 6, 14), "Saturday",
datetime(2025, 6, 15), "Sunday",
datetime(2025, 6, 16), "Monday",
datetime(2025, 6, 17), "Tuesday"
];
data 
| extend MondayWeek=startofweekFromMonday(Date)

Output

DatedayMondayWeek
2025-06-14 00:00:00.0000000Saturday2025-06-09 00:00:00.0000000
2025-06-15 00:00:00.0000000Sunday2025-06-09 00:00:00.0000000
2025-06-16 00:00:00.0000000Monday2025-06-16 00:00:00.0000000
2025-06-17 00:00:00.0000000Tuesday2025-06-16 00:00:00.0000000