# How to use DATEDIFF with logstash jdbc\_static filter

**URL:** <https://discuss.elastic.co/t/how-to-use-datediff-with-logstash-jdbc-static-filter/319293>\
**Category:** Logstash\
**Created:** [November 18, 2022, 12:11pm UTC](https://discuss.elastic.co/t/how-to-use-datediff-with-logstash-jdbc-static-filter/319293 "2022-11-18T12:11:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![niveditakathal](https://avatars.discourse-cdn.com/v4/letter/n/e19b73/32.png) [@niveditakathal](https://discuss.elastic.co/u/niveditakathal)\
**Post date:** [November 18, 2022, 12:11pm UTC](https://discuss.elastic.co/t/how-to-use-datediff-with-logstash-jdbc-static-filter/319293/1 "2022-11-18T12:11:16Z")

</div>

Hi,  
I want to calculate the DATEDIFF under logstash and use it later under filter-\>jdbc\_static -\>local\_lookups query for comparison.

when I tried to

- Calculate DATEDIFF under filter-\>jdbc\_static -\>local\_lookups , I get error as  
[WARN] 2022-11-18 12:11:02.353 [[main]\>worker1] lookup - Exception when executing Jdbc query {:lookup\_id=\>"local-servers", :exception=\>"Java::JavaSql::SQLSyntaxErrorException: Column 'S' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'S' is not a column in the target table.", :backtrace=\>["org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(org/apache/derby/impl/jdbc/S

Code

```auto
filter {
  ..............
  jdbc_static {
]
    local_lookups => [
      {
        id => "local-servers"
        query => "SELECT Id,timeToTestFilesAvailable FROM table01
                  WHERE Id = :testId and timeToTestFilesAvailable > DATEDIFF(s, :startedTime,:updatedTime)"
          parameters => {jobId => "[job_id]" updatedTime => "[updated]" startedTime => "[started]"}
      target => "jobIddetails"
      }
     ]

```

and

- Calculate DATEDIFF in input plugin and use it under filter -\> jdbc\_static , I get Error - [WARN] 2022-11-18 11:48:03.829 [[main]\>worker1] lookup - Parameter field not found in event {:lookup\_id=\>"local-servers", :invalid\_parameters=\>["[inputFileWaitingTime]"]}

Code

```auto
input{
  jdbc {
    .......
    statement => "
      SELECT testId, updated, started, DATEDIFF(s, started,updated) inputFileWaitingTime
      FROM table02 with (nolock)
      WHERE
       updated > :sql_last_value
           AND status <> 0
            "
 } }

```

Can someone please assist me on how I can resolve the issue ?

Regrads,  
Nivedita

---

<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:** [December 16, 2022, 12:11pm UTC](https://discuss.elastic.co/t/how-to-use-datediff-with-logstash-jdbc-static-filter/319293/2 "2022-12-16T12:11:20Z")

</div>

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