Gets the year of a timestamp field.
Parameter | Type | Required | Default Value | Description |
---|---|---|---|---|
as | string | optional[a] | _year | The name of the output field. |
field [b] | string | optional[a] | @timestamp | The name of the input field. |
timezone | string | optional[a] | The time offset to use, for example, -01:00 . If not specified, the query's offset will be used. | |
timezoneField | string | optional[a] | @timezone | The name of the field containing the timezone to use, if not specified the query's timezone will be used. This is ignored if the timezone parameter is passed as well. If this is not defined the timezone offset of the query will be used. |
[a] Optional parameters use their default value unless explicitly set. |
Hide omitted argument names for this function
Omitted Argument NamesThe argument name for
field
can be omitted; the following forms of this function are equivalent:logscale Syntaxtime:year("value")
and:
logscale Syntaxtime:year(field="value")
These examples show basic structure only.
time:year()
Examples
Click
next to an example below to get the full details.Extract Year From Timestamp
Get the year from a timestamp using the
time:year()
function
Query
time:year(timestamp, as=year)
Introduction
In this example, the time:year()
function is used
to extract the year from a specific timestamp 2025-08-27
08:51:51.312
, demonstrating how to get the year value from a
datetime.
Step-by-Step
Starting with the source repository events.
- logscale
time:year(timestamp, as=year)
Extracts the year from the @timestamp field and returns the result in a new field named year. If the
as
parameter is not specified, the result is returned in a field named _year as default. Event Result set.
Summary and Results
The query is used to extract the year from a timestamp, which is useful for analyzing events across different years.
This query is useful, for example, to analyze yearly patterns, group events by year, or investigate long-term trends.
Sample output from the incoming example data:
@timestamp | year |
---|---|
2025-08-27 08:51:51.312 | 2025 |
The result shows how the time:year()
function
extracts the year (in this case 2025
) from the
timestamp.
For visualizing this data, consider using a Bar Chart widget to show
event distribution across years, or a Line Chart widget to display
trends over multiple years. The time:year()
function is often used with other time functions like
time:month()
and
time:dayOfYear()
for complete date analysis.