# Need to convert string into date\_time format

**URL:** https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153
**Category:** Logstash
**Created:** [September 12, 2017, 5:22am UTC](https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153 "2017-09-12T05:22:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![vipinkumar](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@vipinkumar](https://discuss.elastic.co/u/vipinkumar)
#### Post date: [September 12, 2017, 5:22am UTC](https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153/1 "2017-09-12T05:22:26Z")

</div>

Hi All

I am working on csv files and in that file there is a column as DATE/TIME in which the date and time is coming in following format.

```
2017-09-12-0915
YYYY-mm-dd-HHmm

```

I tried to convert this to DATE/TIME to date\_time type by using convert, but in Kibana its type is still string.

Below is my config file.

```
input {
	beats {
        port => "5043"
    }
}
 filter {
	
	if[fields][document] == "ServerIf"
	{
		csv {
			autodetect_column_names => true
                       separator => ","
			convert => {
				"DATE/TIME" => "date_time"
				"EnquiryIn" => "integer"
				"EnquiryOut" => "integer"
				"BalanceUsed" => "integer"
				"BalanceLeft" => "integer"
			   }
               }
         date {
               match => ["DATE/TIME" , "yyyy-MM-dd HH:mm"]
			   target => "DATE/TIME"
        }
	}
}

output {
           elasticsearch {
        hosts => ["localhost:9200"]
    }
}

```

Can anyone help me with this issue...How to convert string to date\_time.

---

<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: [September 12, 2017, 5:31am UTC](https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153/2 "2017-09-12T05:31:55Z")

</div>

> [@vipinkumar](#):
>
> convert =\> {  
> "DATE/TIME" =\> "date\_time"

That's not valid, there's no type like that.

> [@vipinkumar](#):
>
> match =\> ["DATE/TIME" , "yyyy-MM-dd HH:mm"]

That also doesn't match your pattern you originally posted;

> [@vipinkumar](#):
>
> YYYY-mm-dd-HHmm

---

<div class="post-metadata">

### Author: ![vipinkumar](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@vipinkumar](https://discuss.elastic.co/u/vipinkumar)
#### Post date: [September 12, 2017, 5:55am UTC](https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153/3 "2017-09-12T05:55:14Z")

</div>

Hi Mark

Correct me if I'm wrong, but as per this - [https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-date-format.html](https://www.elastic.co/guide/en/elasticsearch/reference/1.7/mapping-date-format.html)

I can use date\_time instead of date right? In fact originally I tried using date\_hour\_minute, but it gave this error:

Pipeline aborted due to error {:exception=\>#\<LogStash::ConfigurationError: Invalid conversion types: date\_hour\_minute\>, :backtrace=\>["/usr/share/logstash/vendor/bundle/jruby/1.9/gems/logstash-filter-csv-3.0.4/lib/logstash/filters/csv.rb:102:in `register'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:281:in`register\_plugin'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:292:in `register_plugins'", "org/jruby/RubyArray.java:1613:in`each'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:292:in `register_plugins'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:302:in`start\_workers'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:226:in `run'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:398:in`start\_pipeline'"]}

As for your second reply, yes you're right I'm actually trying to change the format YYYY-mm-dd-HHmm to yyyy-MM-dd HH:mm. Bases on your reply I guess this isn't the right approach. Could you kindly guide me.

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [September 12, 2017, 5:57am UTC](https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153/4 "2017-09-12T05:57:37Z")

</div>

> I can use date\_time instead of date right?

No. You're referencing the ES documentation which has nothing to do with Logstash.

The date pattern you need is YYYY-MM-dd-HHmm.

---

<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: [September 12, 2017, 6:03am UTC](https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153/5 "2017-09-12T06:03:18Z")

</div>

See also [https://www.elastic.co/guide/en/logstash/5.5/plugins-filters-date.html#plugins-filters-date-match](https://www.elastic.co/guide/en/logstash/5.5/plugins-filters-date.html#plugins-filters-date-match)

---

<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 10, 2017, 6:03am UTC](https://discuss.elastic.co/t/need-to-convert-string-into-date-time-format/100153/6 "2017-10-10T06:03:29Z")

</div>

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