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
Query
setTimeInterval(start=7d, end=1d)
Introduction
The setTimeInterval()
function can be used to set
the time interval and related metadata from within the query instead of
through the QueryJobs API or UI. The time settings of the
setTimeInterval()
function will overwrite whatever
was specified in the QueryJobs API or UI.
setTimeInterval()
must appear in the preamble of
the query, before any other functions, filters, free-text searches, etc.
In this example, the setTimeInterval()
function is
used to define a new time interval before running an ad-hoc query.
Step-by-Step
Starting with the source repository events.
- flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0>Preamble] result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;logscale
setTimeInterval(start=7d, end=1d)
Sets a time interval to start 7 days ago from now and to end 1 day ago from now. As the timezone is not specified, it uses the system's default.
It is possible to explicitly set a timezone instead of using the system's default, in this example, the timezone is explicitly set to
Europe/Copenhagen
:setTimeInterval(start="1w@d", end="now@d", timezone="Europe/Copenhagen")
Event Result set.
Summary and Results
This query demonstrates how to use
setTimeInterval()
to define the timespand from
within the query instead of through the QueryJobs API or UI.