# Query at exact timestamp for different days

**URL:** https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944
**Category:** Fluxlang
**Tags:** influxdb
**Created:** [April 16, 2024, 7:52pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944 "2024-04-16T19:52:37Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![nikiniki](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/nikiniki/32/15472_2.png) [@nikiniki](https://community.influxdata.com/u/nikiniki)
#### Post date: [April 16, 2024, 7:52pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/1 "2024-04-16T19:52:37Z")

</div>

Hi,

im new to flux. How do i filter a data at a specific time from the past 3 days.

specifically i want to query data at exactly 8:00:00 from the past 3 days.

Thank u

---

<div class="post-metadata">

### Author: ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)
#### Post date: [April 16, 2024, 8:31pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/2 "2024-04-16T20:31:52Z")

</div>

@nikiniki What version of InfluxDB are you using? The reason I ask is because different versions support different query languages.

---

<div class="post-metadata">

### Author: ![nikiniki](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/nikiniki/32/15472_2.png) [@nikiniki](https://community.influxdata.com/u/nikiniki)
#### Post date: [April 17, 2024, 6:04am UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/3 "2024-04-17T06:04:42Z")

</div>

I believe its 1.8. Im using it inside Grafana to extract data from InfluxDB

---

<div class="post-metadata">

### Author: ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)
#### Post date: [April 17, 2024, 2:44pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/4 "2024-04-17T14:44:18Z")

</div>

For this specific type of query, you need to use Flux. In InfluxDB 1.8, Flux isn’t enabled by default, so you need to [enable it](https://docs.influxdata.com/influxdb/v1/flux/installation/). You’ll also need to [create a new connection in Grafana](https://docs.influxdata.com/influxdb/v1/tools/grafana/?t=Flux) that uses Flux as the query language.

In you’re query, you need to filter by specific time parts. To do this, you have to evaluate the timestamp of queried data to make sure the hour, minute, and seconds meet your query criteria. You can use functions in the [Flux `date` package](https://docs.influxdata.com/flux/v0/stdlib/experimental/date/), specifically:

- `date.hour()`
- `date.minute()`
- `date.second()`

If your data is more precise than 1s, you’ll need to compare smaller units of time as well.

The query is going to look something like this:

```javascript
from(bucket: "example-db/example-rp")
    |> range(start: -3d)
    |> filter(fn: (r) => r._measurement == "example-measurement")
    |> filter(fn: (r) => date.hour(t: r._time) == 8 and date.minute(t: r._time) == 0 and date.second(t: r._time) == 0)

```

Also note that all timestamps stored in InfluxDB are stored in UTC time.

---

<div class="post-metadata">

### Author: ![nikiniki](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/nikiniki/32/15472_2.png) [@nikiniki](https://community.influxdata.com/u/nikiniki)
#### Post date: [April 18, 2024, 10:27am UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/5 "2024-04-18T10:27:13Z")

</div>

ohhh thanks alot.  
is it also possible to do the filtering with date?  
for example filtering data from the first days of within past three months at 8oclock?

im actually using version 0.194.5. apologies for the mistake

---

<div class="post-metadata">

### Author: ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)
#### Post date: [April 18, 2024, 1:36pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/6 "2024-04-18T13:36:23Z")

</div>

> [@nikiniki](#):
>
> is it also possible to do the filtering with date?  
> for example filtering data from the first days of within past three months at 8oclock?

Yes. Use the exact same method, but with `date.monthDay()` and a query range of 3 months (`3mo`):

```javascript
from(bucket: "example-db/example-rp")
    |> range(start: -3mo)
    |> filter(fn: (r) => r._measurement == "example-measurement")
    |> filter(fn: (r) => date.monthDay(t: r._time) == 1 )
    |> filter(fn: (r) => date.hour(t: r._time) == 8 and date.minute(t: r._time) == 0 and date.second(t: r._time) == 0)

```

---

<div class="post-metadata">

### Author: ![nikiniki](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/nikiniki/32/15472_2.png) [@nikiniki](https://community.influxdata.com/u/nikiniki)
#### Post date: [April 18, 2024, 2:50pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/7 "2024-04-18T14:50:33Z")

</div>

I got this error:  
invalid: error @8:24-8:28: undefined identifier date error @8:55-8:59: undefined identifier date error @8:88-8:92: undefined identifier date error @7:24-7:28: undefined identifier date

I think its because I initially mentioned the wrong version

---

<div class="post-metadata">

### Author: ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)
#### Post date: [April 18, 2024, 2:56pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/8 "2024-04-18T14:56:35Z")

</div>

No, I forgot the import statement that imports the `date` package:

```javascript
import "date"

from(bucket: "example-db/example-rp")
    |> range(start: -3mo)
    |> filter(fn: (r) => r._measurement == "example-measurement")
    |> filter(fn: (r) => date.monthDay(t: r._time) == 1 )
    |> filter(fn: (r) => date.hour(t: r._time) == 8 and date.minute(t: r._time) == 0 and date.second(t: r._time) == 0)

```

---

<div class="post-metadata">

### Author: ![nikiniki](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/nikiniki/32/15472_2.png) [@nikiniki](https://community.influxdata.com/u/nikiniki)
#### Post date: [April 18, 2024, 3:21pm UTC](https://community.influxdata.com/t/query-at-exact-timestamp-for-different-days/33944/9 "2024-04-18T15:21:49Z")

</div>

its worked. Thank you sir ❤
