dayofyear

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

Use the dayofyear function in APL to extract the day number within the year from a datetime value. The function returns an integer from 1 to 365 (or 1 to 366 in a leap year) representing how far into the year the given date falls.

You can use dayofyear to perform year-over-year comparisons by day, analyze seasonal trends, and track how metrics evolve throughout the year. This is especially useful for time-series analysis where you want to align data across multiple years by day number.

Use it when you want to:

  • Compare activity or metrics on the same day across different years.
  • Identify seasonal trends and patterns in log, trace, or security data.
  • Track progress through the year for cumulative reporting.

Usage

Syntax

dayofyear(datetime)

Parameters

NameTypeDescription
datetimedatetimeThe input datetime value.

Returns

An int from 1 to 366 representing the day number within the year.

Use case examples

Track daily request counts across the year to spot high-traffic and low-traffic periods.

Query

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

Run in Playground

Output

day_of_yearrequest_count
1482
2531
3497

This query counts the total number of HTTP requests for each day of the year, helping you identify seasonal traffic patterns.

Monitor trace volume trends by day of the year for each service to detect seasonal performance shifts.

Query

['otel-demo-traces']
| extend day_of_year = dayofyear(_time)
| summarize trace_count = count() by day_of_year, ['service.name']
| sort by day_of_year asc

Run in Playground

Output

day_of_yearservice.nametrace_count
1frontend312
2frontend287
3frontend345

This query tracks how trace volume changes day by day throughout the year for each service, revealing seasonal trends.

Find the busiest days of the year for server errors to identify recurring problem periods.

Query

['sample-http-logs']
| where toint(status) >= 500
| extend day_of_year = dayofyear(_time)
| summarize error_count = count() by day_of_year
| sort by error_count desc

Run in Playground

Output

day_of_yearerror_count
14287
9864
21553

This query ranks days of the year by server error count, helping you pinpoint recurring high-error periods.

  • dayofmonth: Returns the day number within the month from a datetime.
  • dayofweek: Returns the day of the week as an integer, useful for weekday versus weekend analysis.
  • datetime_part: Extracts a specific date part (such as day or year) as an integer.
  • monthofyear: Returns the month number from a datetime, useful for monthly grouping.
  • getyear: Returns the year from a datetime, useful for year-level aggregation.

Other query languages