# How to subtract metric from time value

**URL:** <https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472>\
**Category:** Prometheus\
**Tags:** promql, query-help, kubernetes\
**Created:** [August 13, 2022, 9:06am UTC](https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472 "2022-08-13T09:06:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vomircom](https://avatars.discourse-cdn.com/v4/letter/v/7ea924/32.png) [@vomircom](https://community.grafana.com/u/vomircom)\
**Post date:** [August 13, 2022, 9:06am UTC](https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472/1 "2022-08-13T09:06:03Z")

</div>

I want to see the current pod age. Since there is no metric like that, but only the pod creation time (got that from `kube_pod_created{namespace="$namespace"} * 1000`), I though that maybe I could subtract that from the current time of the host machine. Is that possible? If so, how can I do that?

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [September 29, 2022, 2:08am UTC](https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472/2 "2022-09-29T02:08:16Z")

</div>

yep, there is a way. See [the `time()` function in PromQL](https://prometheus.io/docs/prometheus/latest/querying/functions/#time).

Also check out [this panel in one of our public dashboards](https://play.grafana.org/d/000000029/prometheus-demo-dashboard?orgId=1&refresh=5m&editPanel=10) and then try something like:

`time() - node_boot_time_seconds{job="node", instance=~"$node:.*"}`

or I guess in your case something like:

`time() - kube_pod_created{namespace="$namespace"} * 1000)`

---

<div class="post-metadata">

**Author:** ![saurabhyadav3](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saurabhyadav3](https://community.grafana.com/u/saurabhyadav3)\
**Post date:** [January 17, 2025, 8:48pm UTC](https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472/3 "2025-01-17T20:48:39Z")

</div>

Can you please explain why this does not provide the difference between now and the last time the metric was published?

`(time() - max(timestamp(statsd_gauges_braas_config{config_name="test-db-config"})))/3600`

---

<div class="post-metadata">

**Author:** ![dawiddebowski](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/dawiddebowski/32/49435_2.png) [@dawiddebowski](https://community.grafana.com/u/dawiddebowski)\
**Post date:** [January 18, 2025, 12:22pm UTC](https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472/4 "2025-01-18T12:22:20Z")

</div>

I guess the metric is still being reported - the timestamp takes the timestamp of the point the series returns, so if the series is present now, it’s returning now.

---

<div class="post-metadata">

**Author:** ![saurabhyadav3](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saurabhyadav3](https://community.grafana.com/u/saurabhyadav3)\
**Post date:** [January 19, 2025, 1:23pm UTC](https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472/5 "2025-01-19T13:23:26Z")

</div>

No the last time the metric was pushed was 2 day ago, so ideally it should return the difference in hours but it’s returning some weird number.

so for example: `max(timestamp(statsd_gauges_braas_config{config_name="test-db-config"}))` is giving **1737104452**

and` time()` is giving **1737292800**

but `time() - max(timestamp(statsd_gauges_braas_config{config_name="test-db-config"}))` is giving **548** which is wrong imo.

---

<div class="post-metadata">

**Author:** ![dawiddebowski](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/dawiddebowski/32/49435_2.png) [@dawiddebowski](https://community.grafana.com/u/dawiddebowski)\
**Post date:** [January 19, 2025, 6:50pm UTC](https://community.grafana.com/t/how-to-subtract-metric-from-time-value/70472/6 "2025-01-19T18:50:56Z")

</div>

Can you provide some more info? Screens of base `statsd_gauges_braas_config{config_name="test-db-config"}` as a range query, screens of `max(timestamp(statsd_gauges_braas_config{config_name="test-db-config"}))` and `time()` as instant queries?
