• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

NRQL: Facet results by time

With NRQL, you can create queries that group results across time. For example, you can group results together based on timestamps by separating them into buckets that cover a specified range of dates and times.

When using the time functions from the table below in NRQL queries, the results return in UTC. To adjust the results to your time zone, include the WITH TIMEZONE clause in your query.

For the functions that have an optional format parameter, the accepted values are string and numeric. The default format value will be a string if omitted.

Time-based function

Description

String format

Numeric format

yearOf(attr [, format])

Returns the year of a timestamp.

2023

2023

quarterOf(attr [, format])

Returns the quarter of the year. The returned value includes both the quarter and the year when formatted as a string.

Q1 2014

1

monthOf(attr [, format])

Returns the month and year of the timestamp when formatted as a string, or the numeric month when formatted as a number.

July 2014

7

weekOf(attr)

Returns the week the timestamp occurred by naming the month and day of that week's Monday.

Week of January 15

N/A

weekdayOf(attr [, format])

Returns the day of the week of the timestamp. The returned value loops back at the end of the week, allowing you to look at trends by weekday over time.

Sunday

0

dateOf(attr)

Returns the date of the timestamp. The returned value includes month, day and year.

July 15, 2014

N/A

dayOfMonthOf(attr [, format])

Returns the numeric date within a single month of the timestamp, a value from 1 to 31. The returned value does not include the month.

23

23

daysInMonthOf(attr [, format])

Returns the number of days in the month of the timestamp.

30

30

hourOf(attr [, format])

Returns the hour of the timestamp.

The returned value does not include a prepended 0 for hours between 1am and 9am. This differs from functions and clauses such as SINCE, which accept these hours with a 0 at the start.

6:00, 12:00, 18:00

6, 12, 18

minuteOf(attr [, format])

Returns the minute of the timestamp.

The returned value does not include a prepended 0 for minutes between 1 and 9. This differs from functions and clauses such as SINCE, which accept these minutes with a 0 at the start.

0, 6, 48

0, 6, 48

Facet your NRQL query time range

Tip

In these examples, we use a custom timestamp attribute submitted with PageView events called createdAt. To facet by the time of PageView event ingestion, you could use the timestamp attribute instead.

To create your NRQL query, use a FACET clause with a bucket function that works with a timestamp attribute. Run a standard FACET query, but instead of faceting by an attribute, facet by time. For example:

SELECT count(*) FROM K8sDaemonsetSample FACET monthOf(createdAt)
A screenshot displaying a NRQL query faceted by time

To perform multiple functions within the same query, use NRQL's multi-facet capability:

SELECT count(*) FROM K8sDaemonsetSample FACET dateOf(createdAt), monthOf(createdAt)
NRQL facet by time with two functions

Many time-based functions accept an optional second argument of either string (the default) or numeric, which controls the format of the result value.

SELECT count(*) FROM K8sDaemonsetSample FACET monthOf(createdAt, numeric)

Facet examples

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.