# Now() is sometimes not a function?

**URL:** <https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449>\
**Category:** InfluxDB 2\
**Tags:** influxql\
**Created:** [July 9, 2019, 6:37pm UTC](https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449 "2019-07-09T18:37:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezquat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ezquat/32/5083_2.png) [@ezquat](https://community.influxdata.com/u/ezquat)\
**Post date:** [July 9, 2019, 6:37pm UTC](https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449/1 "2019-07-09T18:37:27Z")

</div>

I want to know when the latest data point is for each value of some other field, and how old it is. Here’s the query I wrote:

```
select now() - time, last("temperature") from temps group by location;

```

But I get

```
ERR: undefined function now()

```

which seems odd because I can use that expression in the “where” clause:

```
select last("temperature") from temps where time < now() - 60m group by location;

```

For what it’s worth, it doesn’t work any better if I apply an aggregate function to time, as follows:

```
select now() - time, last("temperature") from temps group by location;

```

I wonder

(a) Why can’t it simply calculate now() - time for each row in the result? But more importantly  
(b) Is there another way to reach my goal, to get the age of the latest data points after grouping?

---

<div class="post-metadata">

**Author:** ![ezquat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ezquat/32/5083_2.png) [@ezquat](https://community.influxdata.com/u/ezquat)\
**Post date:** [July 15, 2019, 10:28pm UTC](https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449/2 "2019-07-15T22:28:54Z")

</div>

I should clarify: The thing I want to “groupy by” is a tag, not a field. So the grouping, I believe, should be fairly efficient. The problem with certain uses of now() remains.

---

<div class="post-metadata">

**Author:** ![daochun\_zhao](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/daochun_zhao/32/5363_2.png) [@daochun\_zhao](https://community.influxdata.com/u/daochun_zhao)\
**Post date:** [July 21, 2020, 2:40am UTC](https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449/3 "2020-07-21T02:40:31Z")

</div>

@ezquat Did you fixed this, I have the same issue.

---

<div class="post-metadata">

**Author:** ![ezquat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ezquat/32/5083_2.png) [@ezquat](https://community.influxdata.com/u/ezquat)\
**Post date:** [July 31, 2020, 4:03am UTC](https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449/4 "2020-07-31T04:03:00Z")

</div>

@daochun_zhao I never solved it, or found a workaround, alas!

---

<div class="post-metadata">

**Author:** ![jos](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jos/32/3192_2.png) [@jos](https://community.influxdata.com/u/jos)\
**Post date:** [August 3, 2020, 7:48am UTC](https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449/5 "2020-08-03T07:48:57Z")

</div>

Probably best to report as a bug on the slack channel regarding `flux`, or something.

---

<div class="post-metadata">

**Author:** ![ezquat](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ezquat/32/5083_2.png) [@ezquat](https://community.influxdata.com/u/ezquat)\
**Post date:** [August 12, 2020, 12:24am UTC](https://community.influxdata.com/t/now-is-sometimes-not-a-function/10449/6 "2020-08-12T00:24:46Z")

</div>

In another thread, @anaisdg explains this can’t be done in InfluxQL but it can be done in Flux: [How to get how much time elapsed since data point is stored in influxdb](https://community.influxdata.com/t/how-to-get-how-much-time-elapsed-since-data-point-is-stored-in-influxdb/15485)
