# Math operations on field value and time

**URL:** <https://community.influxdata.com/t/math-operations-on-field-value-and-time/6323>\
**Category:** Systems\
**Tags:** influxdb\
**Created:** [August 22, 2018, 9:17am UTC](https://community.influxdata.com/t/math-operations-on-field-value-and-time/6323 "2018-08-22T09:17:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathanp](https://avatars.discourse-cdn.com/v4/letter/n/82dd89/32.png) [@nathanp](https://community.influxdata.com/u/nathanp)\
**Post date:** [August 22, 2018, 9:17am UTC](https://community.influxdata.com/t/math-operations-on-field-value-and-time/6323/1 "2018-08-22T09:17:03Z")

</div>

I want to subtract the timestamp in epoch seconds from a field value (also in epoch seconds). Is this possible?

---

<div class="post-metadata">

**Author:** ![noahcrowley](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/noahcrowley/32/818_2.png) [@noahcrowley](https://community.influxdata.com/u/noahcrowley)\
**Post date:** [August 26, 2018, 4:03pm UTC](https://community.influxdata.com/t/math-operations-on-field-value-and-time/6323/2 "2018-08-26T16:03:49Z")

</div>

No, this is not currently possible, but we always welcome new [feature requests on GitHub](http://github.com/influxdata/influxdb/issues/).

Currently, fields support integers, floats, booleans, and strings, and there is no way to cast a integer, float, or string to a timestamp in order to do the comparison.

What are you trying to accomplish? Would it be possible to perform this calculation before writing the points to the database, and storing the difference instead of the timestamp?

---

<div class="post-metadata">

**Author:** ![nathanp](https://avatars.discourse-cdn.com/v4/letter/n/82dd89/32.png) [@nathanp](https://community.influxdata.com/u/nathanp)\
**Post date:** [October 12, 2018, 3:21am UTC](https://community.influxdata.com/t/math-operations-on-field-value-and-time/6323/3 "2018-10-12T03:21:45Z")

</div>

I am trying to analyze the difference between when my data was logged into database and when it was measured by a node. The time it was logged into the database is recorded in a field value as a unix epoch. The time it was measured is just recorded as the time in influx. Yes it could be precomputed, but that isn’t a very scalable solution for me. It doesn’t make sense to add more and more columns of precomputed derivations of the base data from a storage perspective. Maybe it would make sense from a performance perspective if it were difficult to calculate the derived value or it were used very often - neither of those is the case for me.

---

<div class="post-metadata">

**Author:** ![samaust](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/samaust/32/867_2.png) [@samaust](https://community.influxdata.com/u/samaust)\
**Post date:** [October 14, 2018, 3:18am UTC](https://community.influxdata.com/t/math-operations-on-field-value-and-time/6323/4 "2018-10-14T03:18:48Z")

</div>

I’ll suggest a workaround until such a feature makes its way into InfluxDB.

You could do the calculation client side.  
What client (and programming language) or dashboard software do you use?

---

<div class="post-metadata">

**Author:** ![afausti](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/afausti/32/3887_2.png) [@afausti](https://community.influxdata.com/u/afausti)\
**Post date:** [January 24, 2019, 5:21pm UTC](https://community.influxdata.com/t/math-operations-on-field-value-and-time/6323/5 "2019-01-24T17:21:07Z")

</div>

I had a similar problem in InlfuxQL:

> SELECT time - kafka\_time FROM “kafka”.“autogen”.“mtm1m3-accelerometerdata”

to measure the latency of a message produced by Kafka.

kafka\_time is a Unix timestamp field in the “mtm1m3-accelerometerdata” measurement.

Unfortunately, that query does not work and I ended up extracting the data and computing the latency outside InfluxDB.

Would a query like that work in Flux?
