dayofweek

This page explains how to use the dayofweek function in APL.

Use the dayofweek function in APL to extract the day of the week from a datetime value as an integer. The function returns the number of days since the preceding Sunday, where 0 represents Sunday, 1 represents Monday, and so on up to 6 for Saturday.

You can use dayofweek to group and analyze records by the day of the week. This is especially useful for identifying weekday versus weekend patterns, scheduling-based filtering, and understanding cyclical behavior in your data.

Use it when you want to:

  • Group events by day of the week to spot recurring patterns.
  • Compare weekday and weekend activity in logs, traces, or security data.
  • Filter records to specific days for schedule-based analysis.

Usage

Syntax

dayofweek(datetime)

Parameters

NameTypeDescription
datetimedatetimeThe input datetime value.

Returns

An int representing the number of days since the preceding Sunday (0 for Sunday, 1 for Monday, through 6 for Saturday).

Use case examples

Analyze request volume by day of the week to identify peak traffic days.

Query

['sample-http-logs']
| extend day = dayofweek(_time)
| summarize request_count = count() by day
| sort by day asc

Run in Playground

Output

dayrequest_count
01204
11587
21632

This query groups HTTP log events by the day of the week and counts requests for each day, helping you spot which days see the most traffic.

Compare average span duration across weekdays for a specific service to detect day-of-week performance variations.

Query

['otel-demo-traces']
| extend day = dayofweek(_time)
| summarize avg_duration = avg(duration) by day, ['service.name']
| sort by day asc

Run in Playground

Output

dayservice.nameavg_duration
0frontend00:00:01.3120000
1frontend00:00:01.1840000
2frontend00:00:01.2560000

This query reveals how average span duration varies by day of the week for each service, highlighting potential performance differences on specific days.

Detect anomalous error traffic on specific days of the week by counting client and server errors.

Query

['sample-http-logs']
| where toint(status) >= 400
| extend day = dayofweek(_time)
| summarize error_count = count() by day
| sort by day asc

Run in Playground

Output

dayerror_count
042
128
231

This query counts HTTP errors by day of the week, helping you identify whether certain days experience more failures than others.

  • dayofmonth: Returns the day number within the month from a datetime.
  • dayofyear: Returns the day number within the year from a datetime.
  • datetime_part: Extracts a specific date part (such as day or week) as an integer.
  • startofweek: Returns the start of the week for a datetime, useful for binning events to week boundaries.
  • endofweek: Returns the end of the week for a datetime.

Other query languages