Gets the year of a timestamp field.

ParameterTypeRequiredDefault ValueDescription
asstringoptional[a] _year The name of the output field.
field[b]stringoptional[a] @timestamp The name of the input field.
timezonestringoptional[a]   The time offset to use, for example, -01:00. If not specified, the query's offset will be used.
timezoneFieldstringoptional[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.

[b] The parameter name field can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

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
logscale
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
  1. Starting with the source repository events.

  2. 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.

  3. 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:

@timestampyear
2025-08-27 08:51:51.3122025

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.