# Converting string to date - getting parse error

**URL:** <https://discuss.elastic.co/t/converting-string-to-date-getting-parse-error/84073>\
**Category:** Logstash\
**Created:** [April 29, 2017, 1:35am UTC](https://discuss.elastic.co/t/converting-string-to-date-getting-parse-error/84073 "2017-04-29T01:35:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sraghu1980](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@sraghu1980](https://discuss.elastic.co/u/sraghu1980)\
**Post date:** [April 29, 2017, 1:35am UTC](https://discuss.elastic.co/t/converting-string-to-date-getting-parse-error/84073/1 "2017-04-29T01:35:22Z")

</div>

Hi,

I would like to convert date in string to date in integer. In below example I would like format of "TS" to be similar to that of @timestamp

{  
"type" =\> "perf",  
.............  
"@timestamp" =\> 2017-04-29T01:25:21.279Z,  
.............  
"TS" =\> "Fri Apr 28 16:16:29 2017"  
}

My /etc/logstash/conf.d/logstash.conf has

input {  
file {  
path =\> "/var/www/html/processed/perf.csv"  
type =\> "perf"  
start\_position =\> beginning  
sincedb\_path =\> "/dev/null"  
ignore\_older =\> 0  
}  
}

filter {  
if [type] == "perf" {  
csv {  
separator =\> ","  
columns =\> ['TS','CAPACITY']  
convert =\> {  
'CAPACITY' =\> 'integer'  
}  
}

```
    date {
        match => ["TS", "dd/MMM/YYYY:HH:mm:ss Z"]
    }
}

```

}

output {  
if [type] == "perf" {  
elasticsearch {  
hosts =\> "localhost:9200"  
action =\> "index"  
index =\> "lstash-%{+YYYY.MM.dd}"  
}  
}  
stdout { codec =\> rubydebug }  
}

I am getting following parse error and also TS not converted. Tried multiple methods mentioned in various discussions nothing worked.

{  
"type" =\> "perf",  
..........  
"tags" =\> [  
[0] "\_dateparsefailure"  
],  
"@timestamp" =\> 2017-04-29T01:30:53.806Z,  
..........  
"TS" =\> "Fri Apr 28 16:13:49 2017"  
}

---

<div class="post-metadata">

**Author:** ![sraghu1980](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@sraghu1980](https://discuss.elastic.co/u/sraghu1980)\
**Post date:** [May 1, 2017, 7:37pm UTC](https://discuss.elastic.co/t/converting-string-to-date-getting-parse-error/84073/2 "2017-05-01T19:37:22Z")

</div>

Hi,

Any suggestions to make this working?

-Raghu

---

<div class="post-metadata">

**Author:** ![sraghu1980](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@sraghu1980](https://discuss.elastic.co/u/sraghu1980)\
**Post date:** [May 1, 2017, 9:15pm UTC](https://discuss.elastic.co/t/converting-string-to-date-getting-parse-error/84073/3 "2017-05-01T21:15:06Z")

</div>

Made it working. Since "TIMESTAMP" is "Fri Apr 28 16:16:29 2017"  
Filter should have been:

```
    date {
        match => ["TS", "EEE MMM dd HH:mm:ss YYYY"]
        timezone => "UTC"
        remove_field => "timestamp"
    }

```

Nice documentation. Thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 2, 2017, 3:56am UTC](https://discuss.elastic.co/t/converting-string-to-date-getting-parse-error/84073/4 "2017-05-02T03:56:49Z")

</div>

> [@sraghu1980](#):
>
> "TS" =\> "Fri Apr 28 16:16:29 2017"

Does not match this at all;

> [@sraghu1980](#):
>
> match =\> ["TS", "dd/MMM/YYYY:HH:mm:ss Z"]

You need to recheck that pattern so that it actually matches.

---

<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:** [May 30, 2017, 4:06am UTC](https://discuss.elastic.co/t/converting-string-to-date-getting-parse-error/84073/5 "2017-05-30T04:06:26Z")

</div>

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