# Current date jdbc plugin

**URL:** https://discuss.elastic.co/t/current-date-jdbc-plugin/279154
**Category:** Logstash
**Created:** [July 20, 2021, 11:16am UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154 "2021-07-20T11:16:45Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Jakub\_Kaczmarek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakub_kaczmarek/32/77810_2.png) [@Jakub\_Kaczmarek](https://discuss.elastic.co/u/Jakub_Kaczmarek)
#### Post date: [July 20, 2021, 11:16am UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/1 "2021-07-20T11:16:46Z")

</div>

Hi,  
is it possible to filter query inside jdbc input by CURRENT\_DATE?  
I have the following config:

```auto
input {
    jdbc {
      statement => "SELECT userId, timestamp FROM users;"
      schedule => "* * * * *"
      tags => ["kpi"]
    }
 }

```

I'd like to change it to:

```auto
input {
    jdbc {
      statement => "SELECT userId, timestamp FROM users WHERE timestamp > CURRENT_DATE"; 
      schedule => "* * * * *"
      tags => ["kpi"]
    }
 }

```

where  
CURRENT\_DATE -\> current date in format like that **2021-01-01T00:00:00.000Z**

Is it possible to obtain current date in Logstash?

Regards,  
Kuba

---

<div class="post-metadata">

### Author: ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)
#### Post date: [July 20, 2021, 2:27pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/2 "2021-07-20T14:27:04Z")

</div>

It's a much better idea to do this in the SQL by using TRUNC(sysdate).

> **[Oracle TRUNC Date Function By Practical Examples](https://www.oracletutorial.com/oracle-date-functions/oracle-trunc/)**
>
> This tutorial shows you how to use Oracle TRUNC() function to truncate a date to a specified unit and gives you some practical examples.

`SELECT userId, timestamp FROM users WHERE timestamp >= TRUNC(sysdate)`

---

<div class="post-metadata">

### Author: ![Jakub\_Kaczmarek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakub_kaczmarek/32/77810_2.png) [@Jakub\_Kaczmarek](https://discuss.elastic.co/u/Jakub_Kaczmarek)
#### Post date: [July 21, 2021, 12:44pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/3 "2021-07-21T12:44:16Z")

</div>

Big thanks for the hint and help.  
Do you have idea what to do in case of http\_poller?, here it seems like I'd need somehow to get current date in Logstash,

```auto
http_poller {
  urls => {
    executedsteps => {
      method => get
      url => "https://url/v2.0/data?$filter=timestamp gt CURRENT_DATE&apikey=APIKEY" 
      headers => {
        Accept => "application/json"
      } 
    }
  } 
}

```

Best,  
Kuba

---

<div class="post-metadata">

### Author: ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)
#### Post date: [July 21, 2021, 1:32pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/4 "2021-07-21T13:32:19Z")

</div>

You can use environment variables as well.

> **[Using Environment Variables in the Configuration | Logstash Reference \[7.13\]...](https://www.elastic.co/guide/en/logstash/current/environment-variables.html)**

You will have to set the environment variable before you start logstash to the value you want to input into the url.  
This would technically work for the first JDBC input as well, but in that case it's much better to let SQL do the work.

In shell:

```auto
root@ubuntu-01:~# export CURRENT_DATE=`date --iso-8601`
root@ubuntu-01:~# echo $CURRENT_DATE
2021-07-21

```

Then in your config you can put:  
`url => "https://url/v2.0/data?$filter=timestamp gt ${CURRENT_DATE}&apikey=APIKEY"`

---

<div class="post-metadata">

### Author: ![Jakub\_Kaczmarek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakub_kaczmarek/32/77810_2.png) [@Jakub\_Kaczmarek](https://discuss.elastic.co/u/Jakub_Kaczmarek)
#### Post date: [July 26, 2021, 8:37am UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/5 "2021-07-26T08:37:17Z")

</div>

Thanks for that.  
Do you know how to make CURRENT\_DATE variable to update itself periodically and automatically under Linux?

---

<div class="post-metadata">

### Author: ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)
#### Post date: [July 26, 2021, 1:16pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/6 "2021-07-26T13:16:55Z")

</div>

Since the `CURRENT_DATE` variable is actually running the `date` command it will always be up to date. HOWEVER, I'm not sure if it will update in logstash after logstash starts.  
In the documentation it states:

> - At Logstash startup, each reference will be replaced by the value of the environment variable.

So it is entirely possible that once logstash starts it will stay at a fixed current time.

If you want the current timestamp to update every time in your input then you'll have to restart logstash every day.

---

<div class="post-metadata">

### Author: ![Jakub\_Kaczmarek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakub_kaczmarek/32/77810_2.png) [@Jakub\_Kaczmarek](https://discuss.elastic.co/u/Jakub_Kaczmarek)
#### Post date: [July 26, 2021, 1:29pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/7 "2021-07-26T13:29:46Z")

</div>

export CURRENT\_DATE=`date --date="90 seconds ago" +%Y-%m-%dT%TZ`

As I checked it seems like **CURRENT\_DATE** is calling **date** function once. Since value of CURRENT\_DATE in my case doesn't get updated

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 26, 2021, 5:12pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/8 "2021-07-26T17:12:02Z")

</div>

See also [here](https://discuss.elastic.co/t/http-poller-and-dynamic-time-variable/177663/2).

---

<div class="post-metadata">

### Author: ![Jakub\_Kaczmarek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakub_kaczmarek/32/77810_2.png) [@Jakub\_Kaczmarek](https://discuss.elastic.co/u/Jakub_Kaczmarek)
#### Post date: [July 27, 2021, 9:53am UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/9 "2021-07-27T09:53:40Z")

</div>

> Blockquote  
> You cannot do that with an http\_poller _input_ . However, you could use http\_poller just for its scheduler (or exec, or something else that has a scheduler option), then use an http _filter_ to make the request.

Could you expalin a bit more?  
Maybe with some example?  
Thanks,  
Kuba

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [July 27, 2021, 4:12pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/10 "2021-07-27T16:12:38Z")

</div>

I cannot provide an example, but the idea is that you use a filter with a schedule option to create events periodically. These events need not have any fields of interest. You might even use a prune filter to delete any fields that the input creates.

You could use an exec input to run the date command, in which case obviously you would keep that field. Or else use a ruby filter to run some ruby code that generates a timestamp from 90 seconds ago and add it to the event after the prune.

Then use an http filter to make the call to "[https://url/v2.0/data?$filter=timestamp](https://url/v2.0/data?%24filter=timestamp) gt CURRENT\_DATE&apikey=APIKEY".

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [August 24, 2021, 4:12pm UTC](https://discuss.elastic.co/t/current-date-jdbc-plugin/279154/11 "2021-08-24T16:12:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
