# Multiple format of date to single target

**URL:** <https://discuss.elastic.co/t/multiple-format-of-date-to-single-target/126709>\
**Category:** Logstash\
**Created:** [April 4, 2018, 9:52am UTC](https://discuss.elastic.co/t/multiple-format-of-date-to-single-target/126709 "2018-04-04T09:52:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sridhar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sridhar/32/64860_2.png) [@Sridhar](https://discuss.elastic.co/u/Sridhar)\
**Post date:** [April 4, 2018, 9:52am UTC](https://discuss.elastic.co/t/multiple-format-of-date-to-single-target/126709/1 "2018-04-04T09:52:52Z")

</div>

Hi,

I have the input with 2 date format in same column of csv file.  
3-Mar-18 and Mar-18

below is the config file I created.

--  
date {  
match =\> ["rdate", "d-MMM-yy"]  
target =\> "rdate"  
}

date {  
match =\> ["rdate", "MMM-yy"]  
target =\> "rdate"  
}

mutate{  
convert =\> { "count" =\> "integer" }  
}

--

but Date is not pharseing for 2nd format i.e.. "Mar-18"

```
      "tags" => [
    [0] "_dateparsefailure"

```

Please help...!!!

I have to assign both date format to a single target.

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [April 4, 2018, 11:10am UTC](https://discuss.elastic.co/t/multiple-format-of-date-to-single-target/126709/2 "2018-04-04T11:10:18Z")

</div>

So your CSV looks like this?  
somedata;3-Mar-18  
otherdata;Mar-18  
moredata;3-Mar-18

Then your rdate result at the end should be right and the tag is justified, isn't it? I mean, one of the two filters would have to fail because either the first one is successful and the second is trying to parse a date time object which it cannot parse or the first one doesn't find the right date format and the second one gets it right?  
When I try out your configuration, I get "rdate" =\> 2018-03-02T23:00:00.000Z and "rdate" =\> 2018-02-28T23:00:00.000Z. (March was UTC+1 for where I live, so I guess that makes sense).

If you do not want to get that tag, you will probably have to check the date format with a regex first.  
if([rdate] =~ /^\d{1,2}-[a-zA-Z]{3}-\d{2}$/) {  
...  
}

---

<div class="post-metadata">

**Author:** ![mn\_dev](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@mn\_dev](https://discuss.elastic.co/u/mn_dev)\
**Post date:** [April 4, 2018, 2:36pm UTC](https://discuss.elastic.co/t/multiple-format-of-date-to-single-target/126709/3 "2018-04-04T14:36:32Z")

</div>

According to [https://www.elastic.co/guide/en/logstash/current/plugins-filters-date.html#plugins-filters-date-match](https://www.elastic.co/guide/en/logstash/current/plugins-filters-date.html#plugins-filters-date-match), you should be able to combine the two date filters into one like this:

```
date {
	match => ["rdate", "d-MMM-yy", "MMM-yy"]
	target => "rdate"
}

```

This will then perform the conversion on either format that it finds the field in.

---

<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 2, 2018, 2:36pm UTC](https://discuss.elastic.co/t/multiple-format-of-date-to-single-target/126709/4 "2018-05-02T14:36:39Z")

</div>

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