Skip to main content
Use the endofmonth function in APL to calculate the end of the month for a given datetime value. The function returns a datetime set to the last moment of the final day of the month (23:59:59.9999999), with an optional offset to shift forward or backward by a specified number of months. You can use endofmonth to create monthly time boundaries for aggregation, billing cycles, and reporting. This is especially useful when you need to bucket events into monthly intervals or define month-end deadlines. Use it when you want to:
  • Define end-of-month boundaries for monthly reports and dashboards.
  • Aggregate events to monthly intervals for billing or usage analysis.
  • Build monthly summaries across log, trace, or security datasets.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, there is no direct equivalent to endofmonth. You typically use manual date math with eval and relative_time to calculate the last day of the month. In APL, the endofmonth function handles this directly and supports an optional month offset.
In ANSI SQL, you often use LAST_DAY(timestamp) or combine DATE_TRUNC with interval arithmetic to get the end of the month. In APL, the endofmonth function provides this directly and supports an optional month offset.

Usage

Syntax

Parameters

Returns

A datetime representing the last moment of the month for the given date, shifted by the offset if specified.

Use case examples

Count requests by month boundary to track monthly traffic volume.Query
Run in PlaygroundOutputThis query groups HTTP log events by end-of-month boundaries and counts the total requests in each month.
  • startofmonth: Returns the start of the month for a datetime, useful for defining the beginning of monthly intervals.
  • endofday: Returns the end of the day for a datetime.
  • endofweek: Returns the end of the week for a datetime.
  • endofyear: Returns the end of the year for a datetime.
  • monthofyear: Returns the month number from a datetime, useful for month-based grouping.