# Logstash - not able to insert date in this format 'YYYY-MM-DD hh:mm:ss'

**URL:** <https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405>\
**Category:** Logstash\
**Created:** [September 3, 2020, 2:31pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405 "2020-09-03T14:31:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SwatiD](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@SwatiD](https://discuss.elastic.co/u/SwatiD)\
**Post date:** [September 3, 2020, 2:31pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/1 "2020-09-03T14:31:54Z")

</div>

My date format is `YYYY-MM-DD hh:mm:ss` but logstash is changing this to something like `2020-09-03T05:03:00.000Z` .  
I have use this filter in logstash config file

filter {  
date {  
match =\> ["endDate", "YYYY-MM-DD hh:mm:ss"]  
timezone =\> "Asia/Kolkata"  
target =\> "endDate"  
}  
}

still date not getting in require format

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 3, 2020, 3:06pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/2 "2020-09-03T15:06:12Z")

</div>

What does your mapping look like for this [date data type](https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html)? If you don't provide a format it will convert it to what you are seeing by default.

```auto
{
  "mappings": {
    "properties": {
      "endDate": {
        "type": "date",
        "format": "YYYY-MM-DD hh:mm:ss"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![SwatiD](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@SwatiD](https://discuss.elastic.co/u/SwatiD)\
**Post date:** [September 3, 2020, 3:17pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/3 "2020-09-03T15:17:36Z")

</div>

My mapping is

PUT indexname  
{  
"mappings": {  
"dynamic\_date\_formats": ["YYYY-MM-DD hh:mm:ss"]  
}  
}

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 3, 2020, 4:02pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/4 "2020-09-03T16:02:39Z")

</div>

Can you post a sample of your endDate field?

---

<div class="post-metadata">

**Author:** ![SwatiD](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@SwatiD](https://discuss.elastic.co/u/SwatiD)\
**Post date:** [September 4, 2020, 5:15am UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/5 "2020-09-04T05:15:57Z")

</div>

This is my logstash config file  
input {  
jdbc {  
jdbc\_driver\_library =\>"mysql-connector-java-8.0.16/mysql-connector-java-8.0.16.jar"  
jdbc\_driver\_class =\> "com.mysql.cj.jdbc.Driver"  
jdbc\_connection\_string =\> "jdbc:mysql://localhost:3306/testdb?serverTimezone=Asia/Kolkata&zeroDateTimeBehavior=convertToNull&useCursorFetch=true"  
jdbc\_user =\> "root"  
jdbc\_password =\> ""  
tracking\_column =\> "unix\_ts\_in\_secs"  
use\_column\_value=\>true  
jdbc\_fetch\_size =\> 50000  
jdbc\_default\_timezone =\> "Asia/Kolkata"  
statement =\> "SELECT  
applicationNo,  
endDate,  
UNIX\_TIMESTAMP(modifyOn) AS unix\_ts\_in\_secs  
FROM  
`ccmaping`  
WHERE  
(UNIX\_TIMESTAMP(modifyOn) \> :sql\_last\_value AND modifyOn \< NOW())"  
schedule =\> "\*/5 \* \* \* \* \*"  
}   
}  
filter {  
date {  
match =\> ["endDate", "YYYY-MM-DD hh:mm:ss"]  
timezone =\> "Asia/Kolkata"  
target =\> "endDate"  
}  
}  
output {  
elasticsearch {  
document\_type =\> "\_doc"  
document\_id=\> "%{id}"  
index =\> "testindex"  
hosts =\> ["[http://localhost:9200](http://localhost:9200)"]

```
	}
stdout{
	codec => rubydebug
}

```

}

Sample data for endDate would be like '2020-01-20 14:01:31'  
Logstash converting it into '2020-01-20T08:31:31.000Z'

I want the same format i.e YYYY-MM-DD hh:mm:ss

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 4, 2020, 12:13pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/6 "2020-09-04T12:13:05Z")

</div>

What are you going to use this field for? If you want it as a date then that format will work great.

If you want it for display purposes then I would just make it a string and never convert to a date.

---

<div class="post-metadata">

**Author:** ![SwatiD](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@SwatiD](https://discuss.elastic.co/u/SwatiD)\
**Post date:** [September 4, 2020, 12:20pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/7 "2020-09-04T12:20:56Z")

</div>

I want to filter data according to endDate i.e and want to show result in 'yyyy-MM-dd HH:mm:ss' format only

"bool":{  
"must":{  
{  
"range":{  
"enddate":{  
"gte" : '2020-09-01 13:00:00',  
"lte" : '2020-09-04 13:00:00',  
"format" : "yyyy-MM-dd HH:mm:ss"  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [September 4, 2020, 2:52pm UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/8 "2020-09-04T14:52:03Z")

</div>

Think I understand what you want to do now. The `date filter` is used to parse something to an ISO8601 timestamp. I don't think that is what you want.

In Logstash just leave your field as is and when then when it is mapped it will read it as a date.

**Data**

```auto
{
     "endDate": "2020-01-18 14:01:31"
}

```

**Mapping**

```auto
{
  "mappings": {
    "properties": {
      "endDate": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      }
    }
  }
}

```

**Query**

```auto
{
  "query": {
    "range": {
      "endDate": {
        "gte": "2020-01-17 14:01:32", 
        "lte": "2020-01-19 14:01:31"
      }
    }
  }
}

```

**Result**

```auto
"_source" : {
  "endDate" : "2020-01-18 14:01:31"
}

```

---

<div class="post-metadata">

**Author:** ![SwatiD](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@SwatiD](https://discuss.elastic.co/u/SwatiD)\
**Post date:** [September 7, 2020, 6:37am UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/9 "2020-09-07T06:37:10Z")

</div>

Thanks for the reply.

This is working fine If I use kibana console to insert data into elasticsearch.but throwing issue if I use logstash to insert data.Showing below error.logstash is ignoring my date format mappings and insert date fields in default date format

_failed to parse date field [2020-01-24 21:00:00] with format [strict\_date\_optional\_time||epoch\_millis]: [failed to parse date field [2020-01-24 21:00:00] with format [strict\_date\_optional\_time||epoch\_millis]]_

---

<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:** [October 5, 2020, 6:37am UTC](https://discuss.elastic.co/t/logstash-not-able-to-insert-date-in-this-format-yyyy-mm-dd-hhss/247405/10 "2020-10-05T06:37:15Z")

</div>

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