---
title: "Built-in variables | Grafana documentation"
description: "Use Grafana built-in variables to reference dashboard metadata, time ranges, intervals, and user context in queries, links, and panel titles."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Built-in variables

Grafana has built-in variables that you can use in expressions in the query editor. These variables are globally-scoped so you can use them in any dashboard. This page lists them in alphabetical order and defines them. Most variables are useful in queries, dashboard links, panel links, and data links—but some, like `$__url_time_range`, are only intended for use in links, not query editors.

## `$__dashboard`

This variable is the name of the current dashboard.

## `$__from` and `$__to`

Grafana has built-in time range variables: `$__from` and `$__to`. They’re always interpolated as epoch milliseconds by default, but you can control date formatting.

Expand table

| Syntax                   | Example result           | Description                                                                                                                                                     |
|--------------------------|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `${__from}`              | 1594671549254            | Unix millisecond epoch                                                                                                                                          |
| `${__from:date}`         | 2020-07-13T20:19:09.254Z | No arguments, defaults to ISO 8601/RFC 3339                                                                                                                     |
| `${__from:date:iso}`     | 2020-07-13T20:19:09.254Z | ISO 8601/RFC 3339                                                                                                                                               |
| `${__from:date:seconds}` | 1594671549               | Unix seconds epoch                                                                                                                                              |
| `${__from:date:YYYY-MM}` | 2020-07                  | Any custom [date format](https://momentjs.com/docs/#/displaying/) that doesn’t include the `:` character. Uses browser time. Use `:date` or `:date:iso` for UTC |

The syntax above also works with `${__to}`.

You can use this variable in URLs, as well. For example, you can send a user to a dashboard that shows a time range from six hours ago until the current time: `https://play.grafana.org/d/000000012/grafana-play-home?viewPanel=2&orgId=1?from=now-6h&to=now`

## `$__interval`

You can use the `$__interval` variable as a parameter to group by time for InfluxDB, MySQL, Postgres, and MSSQL; as a Date histogram interval for Elasticsearch; or as a *summarize* function parameter for Graphite.

Grafana automatically calculates an interval that you can use to group by time in queries. When there are more data points than a graph can show, grouping by a larger interval makes queries more efficient. Grouping by 1 day is more efficient than grouping by 10s when you look at 3 months of data. The graph looks the same, and the query is faster. Grafana calculates `$__interval` from the time range and the graph width in pixels.

Approximate Calculation: `(to - from) / resolution`

For example, when the time range is 1 hour and the graph is full screen, then the interval might be calculated to `2m` - points are grouped in 2 minute intervals. If the time range is 6 months and the graph is full screen, then the interval might be `1d` (1 day) - points are grouped by day.

In the InfluxDB data source, the legacy variable `$interval` is the same variable. You should use `$__interval` instead.

The InfluxDB and Elasticsearch data sources have `Group by time interval` fields that are used to hard code the interval or set the minimum limit for the `$__interval` variable by using the `>` syntax, for example `>10m`.

## `$__interval_ms`

This variable is the `$__interval` variable in milliseconds, not a time interval formatted string. For example, if the `$__interval` is `20m` then the `$__interval_ms` is `1200000`.

## `$__name`

This variable is only available in the **Singlestat** panel and you can use it in the prefix or suffix fields on the Options tab. Grafana replaces the variable with the series name or alias.

> Note
> 
> The **Singlestat** panel is no longer available from Grafana 8.0.

## `$__namespace`

This variable is the Kubernetes namespace that Grafana uses internally to identify the current organization. In Grafana Cloud, the value might be `stacks-123`. In self-managed Grafana, it’s `default` for the default organization and `org-<id>` for other organizations. Use the variable in API URLs that require an organization namespace, such as `/apis/<group>/<version>/namespaces/${__namespace}/<resource>`.

> Note
> 
> This variable is only interpolated in dashboards. In Explore, alert rule query editors, and other views outside a dashboard, it’s left as written.

## `$__org`

This variable is the ID of the current organization. `${__org.name}` is the name of the current organization.

## `$__user`

`${__user.id}` is the ID of the current user. `${__user.login}` is the login handle of the current user. `${__user.email}` is the email for the current user.

## `$__range`

Currently only supported for Prometheus and Loki data sources. This variable represents the range for the current dashboard. It’s calculated by `to - from`. It has a millisecond and a second representation called `$__range_ms` and `$__range_s`.

## `$__rate_interval`

Currently only supported for Prometheus data sources. Use the `$__rate_interval` variable in the rate function. Refer to [Prometheus query variables](/docs/grafana/next/datasources/prometheus/template-variables/#use-__rate_interval) for details.

## `$__rate_interval_ms`

This variable is the `$__rate_interval` variable in milliseconds, not a time-interval-formatted string. For example, if the `$__rate_interval` is `20m` then the `$__rate_interval_ms` is `1200000`.

## `$timeFilter` or `$__timeFilter`

The `$timeFilter` variable returns the active time range selection as an expression. For example, the time range interval `Last 7 days` expression is `time > now() - 7d`.

It’s used in several places, including:

- The `WHERE` clause for the InfluxDB data source. Grafana adds it automatically to InfluxDB queries when in Query Editor mode. You can add it manually in Text Editor mode: `WHERE $timeFilter`.
- Log Analytics queries in the Azure Monitor data source.
- SQL queries in MySQL, Postgres, and MSSQL.
- The `$__timeFilter` variable is used in the MySQL data source.

## `$__timezone`

The `$__timezone` variable returns the active time zone selection, either `utc` or an entry from the IANA time zone database, such as `America/New_York`.

If the active time zone selection is *Browser Time*, Grafana tries to determine your browser time zone.

## `$__url_time_range`

The `$__url_time_range` variable returns the current dashboard time range as URL query parameters. It’s intended for use in data links and panel links, not in query editors.

The variable expands to a string like `from=1607687293000&to=1607687293100`, where the values are Unix millisecond timestamps matching the current time range selection.

You must include the `?` or `&` separator yourself when constructing URLs:

Expand table

| Usage                                                   | Example result                                                          |
|---------------------------------------------------------|-------------------------------------------------------------------------|
| `https://example.com/d/abc?${__url_time_range}`         | `https://example.com/d/abc?from=1594671549254&to=1594672349254`         |
| `https://example.com/d/abc?orgId=1&${__url_time_range}` | `https://example.com/d/abc?orgId=1&from=1594671549254&to=1594672349254` |

To link to another dashboard while preserving the current time range, follow this pattern:

text ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```text
https://your-grafana/d/other-dashboard?${__url_time_range}
```

To also pass a variable value from the current dashboard, follow this pattern:

text ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```text
https://your-grafana/d/other-dashboard?{__url_time_range}&var-host= {host}
```

> Note
> 
> `$__url_time_range` always uses Unix millisecond epoch timestamps. To include only the start or end of the time range with specific formatting, use [`$__from` and `$__to` variables](#__from-and-__to) instead.
