# Couldn't convert date\_time type

**URL:** https://discuss.elastic.co/t/couldnt-convert-date-time-type/128276
**Category:** Logstash
**Created:** [April 17, 2018, 2:40am UTC](https://discuss.elastic.co/t/couldnt-convert-date-time-type/128276 "2018-04-17T02:40:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hskang](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@hskang](https://discuss.elastic.co/u/hskang)
#### Post date: [April 17, 2018, 2:40am UTC](https://discuss.elastic.co/t/couldnt-convert-date-time-type/128276/1 "2018-04-17T02:40:47Z")

</div>

I want to convert the column from string to date\_time but nothing changed.

log

```auto
2018-04-13T05:37:52.874Z|8|200|0|USR|1510|[Fire...|104|2018-04-12T11:05:15.352Z|201|Pacific|1510|[Fire...|R110|2018-04-12T11:05:59.352Z

```

configuration(filter part)

```auto
filter {
	if "mongo" in [tags] {
		csv{
			separator => "|"
			columns => [
				"logTime",
				"transactionId",
				"resultCode",
				"reqId",
				"reqType",
				"reqCode",
				"reqParam",
				"reqBytes",
				"reqTime",
				"resId",
				"resType",
				"resCode",
				"resParam",
				"resBytes",
				"resTime"
			]
			convert => {
				"logTime" => "date_time"
				"reqTime" => "date_time"
				"resTime" => "date_time"
			}  
			remove_field => ["@version","host","path"]
		}
	}
}

```

![10](https://us1.discourse-cdn.com/elastic/original/3X/5/7/57a02d74c1a344fea3bacb3ab0bb1b389b325b51.png)

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [April 17, 2018, 8:30am UTC](https://discuss.elastic.co/t/couldnt-convert-date-time-type/128276/2 "2018-04-17T08:30:20Z")

</div>

I presume the output you show is from a Mongo data explorer of some kind.  
I presume that you are using the mongodb output. You should really give as much detail as possible.

I don't think you can assume that the CSV filter convert are failing, the mongo output converts LogStash::Timestamp to String by default.  
From the comments in the code..

```auto
  # If true, store the @timestamp field in MongoDB as an ISODate type instead
  # of an ISO8601 string. For more information about this, see
  # http://www.mongodb.org/display/DOCS/Dates.
  config :isodate, :validate => :boolean, :default => false

```

A better link is [https://docs.mongodb.com/manual/reference/bson-types/index.html#date](https://docs.mongodb.com/manual/reference/bson-types/index.html#date)

Our docs on [the isodate setting](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-mongodb.html#plugins-outputs-mongodb-isodate).

---

<div class="post-metadata">

### Author: ![hskang](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@hskang](https://discuss.elastic.co/u/hskang)
#### Post date: [April 17, 2018, 11:20am UTC](https://discuss.elastic.co/t/couldnt-convert-date-time-type/128276/3 "2018-04-17T11:20:24Z")

</div>

I've solved the problem.  
thank you

```auto
filter {
	if "mongo" in [tags] {
		csv{
			separator => "|"
			columns => [
				"logTime",
                                .
                                .
 				"reqTime",
                                .
                                .
				"resTime"
			]
			convert => {
				"logTime" => "date_time"
				"reqTime" => "date_time"
				"resTime" => "date_time"
			}  
			remove_field => ["@version","host","path"]
		}
        date{
        	match => ["logTime", "ISO8601"]
			target => "logTime"
        }
        date{
        	match => ["reqTime", "ISO8601"]
			target => "reqTime"
        }
        date{
        	match => ["resTime", "ISO8601"]
			target => "resTime"
        }
	}
}

output {  
	stdout {
    		codec => rubydebug
  	}
	if "mongo" in [tags] {
		mongodb { 
			collection => "ServiceLog" 
			database => "log"
			isodate => true
			uri => "mongodb://localhost"
		}
	}
}

```

---

<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 15, 2018, 11:20am UTC](https://discuss.elastic.co/t/couldnt-convert-date-time-type/128276/4 "2018-05-15T11:20:33Z")

</div>

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