Date and time functions

Date and time functions expose the evaluation clock and sample timestamps, enabling age calculations and time-dependent alert conditions. All values are UTC.

day_of_month

Returns the day of the month (1–31), UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

day_of_month([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current day of the month in UTC.

day_of_month()
Expected output
Value

4

All date functions operate in UTC.

day_of_week

Returns the day of the week (0–6, Sunday = 0), UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

day_of_week([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current day of the week in UTC.

day_of_week()
Expected output
Value

6

All date functions operate in UTC.

day_of_year

Returns the day of the year (1–366), UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

day_of_year([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current day of the year in UTC.

day_of_year()
Expected output
Value

185

All date functions operate in UTC.

days_in_month

Returns the number of days in the month (28–31), UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

days_in_month([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current number of days in the month in UTC.

days_in_month()
Expected output
Value

31

All date functions operate in UTC.

hour

Returns the hour of the day (0–23), UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

hour([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current hour of the day in UTC.

hour()
Expected output
Value

19

All date functions operate in UTC.

minute

Returns the minute of the hour (0–59), UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

minute([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current minute of the hour in UTC.

minute()
Expected output
Value

55

All date functions operate in UTC.

month

Returns the month of the year (1–12), UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

month([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current month of the year in UTC.

month()
Expected output
Value

7

All date functions operate in UTC.

time

Returns the evaluation timestamp of the query in Unix seconds, as a scalar. The standard building block for age calculations: time() - <timestamp metric> gives seconds since an event.

Syntax

time()
none

Example

Return the evaluation time as a chartable vector.

vector(time())
Expected output
Value

1,783,194,966

time() is a scalar; wrap it in vector() to chart it or compare it against vectors.

timestamp

Replaces every sample’s value with that sample’s timestamp in Unix seconds, preserving labels. Combined with time(), it measures data freshness: how old is the newest sample of each series.

Syntax

timestamp(<expr>)
none

Example

Measure the age in seconds of the newest query-service goroutine sample — small values mean fresh data.

time() - max(timestamp(go_goroutines{app_kubernetes_io_name="query-service"}))
Expected output
Value

0

year

Returns the year, UTC, for each sample’s timestamp. Called with no argument, it uses the query evaluation time. Date functions gate time-dependent alert rules — for example, suppressing a batch-job alert on weekends.

Syntax

year([<vector of timestamps>])
none

Parameters

Parameter Required Description

<vector>

Optional

Timestamps to convert; defaults to the evaluation time.

Example

Return the current year in UTC.

year()
Expected output
Value

2,026

All date functions operate in UTC.