getmonth

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

Use the getmonth function in APL to extract the month number from a datetime value. The function returns an integer from 1 to 12, where 1 represents January and 12 represents December.

You can use getmonth to group records by month when analyzing seasonal patterns, monthly trends, or periodic fluctuations in your data. This is useful for dashboards, monthly reporting, and cohort analysis.

Use it when you want to:

  • Aggregate events by month for trend analysis.
  • Compare metrics across months to detect seasonal patterns.
  • Create monthly summaries across log, trace, or security datasets.

Usage

Syntax

getmonth(datetime)

Parameters

NameTypeDescription
datetimedatetimeThe input datetime value.

Returns

An int from 1 to 12 representing the month number.

Use case examples

Analyze HTTP request volume by month to identify traffic patterns throughout the year.

Query

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

Run in Playground

Output

monthrequest_count
14521
24187
34893

This query groups HTTP log entries by month number and counts the requests in each month.

Compare monthly average span durations by service to spot performance changes across months.

Query

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

Run in Playground

Output

monthservice.nameavg_duration
1frontend00:00:01.2340000
2frontend00:00:01.1890000
3frontend00:00:01.3020000

This query calculates the average span duration per month for each service, helping you track monthly performance trends.

Find which months have the most server errors to uncover seasonal reliability patterns.

Query

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

Run in Playground

Output

montherror_count
789
1276
354

This query identifies the months with the highest number of server errors, sorted by error count in descending order.

  • monthofyear: Returns the month number from a datetime. Equivalent to getmonth.
  • getyear: Extracts the year part from a datetime as an integer.
  • dayofmonth: Returns the day of the month from a datetime.
  • startofmonth: Returns the start of the month for a datetime, useful for monthly binning.
  • endofmonth: Returns the end of the month for a datetime value.

Other query languages