# How to add timestamp from SQL query to grafana alert body?

**URL:** <https://community.grafana.com/t/how-to-add-timestamp-from-sql-query-to-grafana-alert-body/155397>\
**Category:** Alerting\
**Tags:** alerting\
**Created:** [July 30, 2025, 12:59pm UTC](https://community.grafana.com/t/how-to-add-timestamp-from-sql-query-to-grafana-alert-body/155397 "2025-07-30T12:59:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emailbot348](https://avatars.discourse-cdn.com/v4/letter/e/ad7895/32.png) [@emailbot348](https://community.grafana.com/u/emailbot348)\
**Post date:** [July 30, 2025, 12:59pm UTC](https://community.grafana.com/t/how-to-add-timestamp-from-sql-query-to-grafana-alert-body/155397/1 "2025-07-30T12:59:38Z")

</div>

I am in Grafana V11, and I’m really struggling to get the time column from the query into the alert body. I have read through numerous topics and gone through the documentation, I have been at this for 2 days tinkering on and cannot get it to work.

I have a simple SQL query returning 2 columns, time and value for the past hour:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/2/c/2c2f3a55deaf304a4d8ae0b30ada2965c52346fb.png)

I have 2 expressions that get the last value and trigger the alert when above a threshold:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/c/d/cdf2b0c9debb97ae67255cd755a08c6ba0303915.png)

Literally all I want to do is have the alert message like this example:  
Meter crossed threshold at 2025-07-30 13:02:44.607.

I have a contact point set up, and I have tried using labels and annotations but cannot seem to get the timestamp to come through. Can anyone help me do this, feel like it’s definitely possible, I just haven’t cracked it yet.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![pepecano](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/pepecano/32/40676_2.png) [@pepecano](https://community.grafana.com/u/pepecano)\
**Post date:** [September 25, 2025, 5:56pm UTC](https://community.grafana.com/t/how-to-add-timestamp-from-sql-query-to-grafana-alert-body/155397/2 "2025-09-25T17:56:52Z")

</div>

> [@emailbot348](#):
>
> Meter crossed threshold at 2025-07-30 13:02:44.607.

This one is a bit tricky. The situation is that your SQL query returns rows of `timestamp + value`. Grafana Alerting interprets this as time series data, like:

```auto
Series 1 = [{ts1, v1}, {ts2, v2}, {ts3, v3} …]

```

 ![Screenshot 2025-09-25 at 19.44.32](https://us1.discourse-cdn.com/grafana/original/3X/b/a/ba506b93f7a4537a73411fd814e738ac2d88796a.png)

If you instead cast the timestamp as text, Grafana will treat the result as **tabular data**. That changes how the alerting processes it (see screenshots for comparison).

 ![Screenshot 2025-09-25 at 19.44.13](https://us1.discourse-cdn.com/grafana/original/3X/b/c/bc342b5fcd5f26b9c29db85f20d5cda1ffe081d1.png)

More details on how table data works in alerting are this [example on tabular data](https://grafana.com/docs/grafana/latest/alerting/best-practices/table-data/).

When handled as tabular data, `ts` becomes a label, so you can reference it in your notification template like:

`{{ range .Alerts -}}`  
`Meter crossed threshold at {{ .Labels.ts_text }} {{ end -}}`

Hope this helps!
