Available:setTimeInterval() v1.171.0

The setTimeInterval() function is available from v1.171.0

setTimeInterval() can be used to set the query's time interval and related time settings from within the query string. When used, the query time specified in the query string will override the settings from the UI or query API.

ParameterTypeRequiredDefault ValueDescription
endstring,time pointoptional[a] now End time of query. When specified, it overrides the end time from the query API.
start[b]string,time pointrequired   Start time of query. When specified, it overrides the start time from the query API.
timezonestring,time zone nameoptional[a]   Time zone name. When specified, overrides the timezone set from the query API. For a list of timezone names, see the table “Supported Timezones”.

[a] Optional parameters use their default value unless explicitly set.

[b] The parameter name start can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

Using setTimeInterval() offers several advantages:

  • Query users can specify time ranges directly in query strings. The feature enables copying and sharing query strings with other users, who can recreate the search in different views and/or clusters (with different URLs).

  • Dashboard creators can specify time ranges in query strings. The feature allows setting the static time range for the widgets.

This is a metadata query function that does not process events. It is only used for setting the time interval and related metadata from within the query instead of through the Query Jobs API or the UI.

Using setTimeInterval() affects both the API and the UI, as follows.

Using setTimeInterval() also overrides the time controls in the UI. See Change Time Interval and Shared Time Selector for more information.

Validation Rules/Known Limitations

The setTimeInterval() function requires specific validation rules for correct usage.

  • Must appear in the preamble of the query — that is, before any other functions, filters, free-text searches, etc.

  • Must appear before any defineTable() definitions.

  • Must appear at most once in a query.

  • Cannot appear inside join()/defineTable() subqueries. To set a different time range for the ad-hoc table/join subquery, use the start and end parameters that are supported in these functions.

  • Same restrictions as the API time interval apply, that is:

    • In a live query start must be relative, and end must be now

    • If the user has search limitations (for example, trial users can only search 7 days back), these limitations still apply

  • setTimeInterval() is only supported in ad-hoc searches and on dashboards. In particular, setTimeInterval() is not supported in:

Click + next to an example below to get the full details.

Set Time Interval From Within Query

Set the time interval and related metadata from within the query instead of through the QueryJobs API or UI

Set Time Interval From Within Query with defineTable()

Set the time interval and related metadata from within the query instead of through the test QueryJobs API or UI using the defineTable() function