# "\_dateparsefailure"

**URL:** <https://discuss.elastic.co/t/dateparsefailure/277700>\
**Category:** Logstash\
**Created:** [July 3, 2021, 8:16am UTC](https://discuss.elastic.co/t/dateparsefailure/277700 "2021-07-03T08:16:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RoteEdition](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roteedition/32/91103_2.png) [@RoteEdition](https://discuss.elastic.co/u/RoteEdition)\
**Post date:** [July 3, 2021, 8:16am UTC](https://discuss.elastic.co/t/dateparsefailure/277700/1 "2021-07-03T08:16:39Z")

</div>

Hi there,  
i am trying to parse a .CSV file with a pretty horrible date format.  
I am using the Date filter:

```auto
    date {
        match => ["HelperDate", "dMMyyyy", "ddMMyyyy"]
      }
	

```

Some example data:

6112019 -\> "\_dateparsefailure"  
1122019 -\> "\_dateparsefailure"  
8032019 -\> "\_dateparsefailure"  
29112019 -\> works  
26112019 -\> works  
28022019 -\> works

I think the problem only occurs on single-digit days. I thought "d" would do the job.

Maybe somebody knows how to fix the problem.  
I was thinking about a possible workaround: Adding a 0 before the whole field, when the field length is only 7 digits. Unfortunately I am still a beginner, so I don't know if this is even possible.

Thank you for helping me out.  
If more information is needed, please let me know.

Kind Regards  
Marvin

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [July 3, 2021, 2:09pm UTC](https://discuss.elastic.co/t/dateparsefailure/277700/2 "2021-07-03T14:09:53Z")

</div>

I simulated your `date` filter and the dates with single digit also fails for me.

You can implemente your workaround, add a 0 if the date has 7 digits, using a conditional and some mutate filters.

The following config will do:

```auto
if [HelperDate] =~ /^[0-9]{7}$/ {
    mutate {
        rename => { "HelperDate" => "oldHelperDate" }
    }
    mutate {
        add_field => { "HelperDate" => "0%{oldHelperDate}" }
    }
}

```

The `if` condition will check your field `HelperDate` against a regex that will test if it is a sequence of 7 digits, if this is true, the first mutate will rename your field and the second one will recreate the `HelperDate` field adding a `0` in front of the `oldHelperDate` field.

If you want you can remove this `oldHelperDate` field with a new mutate:

```auto
mutate {
    remove_field => ["oldHelperDate"]
}

```

Simulating this config for the values `29112019` and `61120219` I've got the following output.

```auto
{
    "oldHelperDate" => "6112019",
       "@timestamp" => 2019-11-06T03:00:00.000Z,
         "@version" => "1",
       "HelperDate" => "06112019",
             "host" => "elk"
}
{
    "@timestamp" => 2019-11-29T03:00:00.000Z,
      "@version" => "1",
    "HelperDate" => "29112019",
          "host" => "elk"
}

```

Since your date field does not have a time, logstash will use the time `00:00:00.000Z` and will convert it to `UTC` according to the servers time zone.

In my case I'm on UTC-3, so the time of my date will be `03:00:00.000Z`.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 3, 2021, 4:23pm UTC](https://discuss.elastic.co/t/dateparsefailure/277700/3 "2021-07-03T16:23:02Z")

</div>

> [@RoteEdition](#):
>
> I think the problem only occurs on single-digit days. I thought "d" would do the job.

See [here](https://discuss.elastic.co/t/logstash-date-plugin-not-working-as-expected/262525/4). Even for "d" or "H" the parser will consume two digits if they are available, and there are no months with 61 days, so it fails to parse 6112019.

---

<div class="post-metadata">

**Author:** ![RoteEdition](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roteedition/32/91103_2.png) [@RoteEdition](https://discuss.elastic.co/u/RoteEdition)\
**Post date:** [July 3, 2021, 5:12pm UTC](https://discuss.elastic.co/t/dateparsefailure/277700/4 "2021-07-03T17:12:21Z")

</div>

Thank you so much. Works like a charm! You made my day!

---

<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:** [July 31, 2021, 5:12pm UTC](https://discuss.elastic.co/t/dateparsefailure/277700/5 "2021-07-31T17:12:38Z")

</div>

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