# No implicit conversion of Fixnum into String when adding days to a date

**URL:** <https://discuss.elastic.co/t/no-implicit-conversion-of-fixnum-into-string-when-adding-days-to-a-date/174690>\
**Category:** Logstash\
**Created:** [March 31, 2019, 8:58pm UTC](https://discuss.elastic.co/t/no-implicit-conversion-of-fixnum-into-string-when-adding-days-to-a-date/174690 "2019-03-31T20:58:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roblopes](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@roblopes](https://discuss.elastic.co/u/roblopes)\
**Post date:** [March 31, 2019, 8:58pm UTC](https://discuss.elastic.co/t/no-implicit-conversion-of-fixnum-into-string-when-adding-days-to-a-date/174690/1 "2019-03-31T20:58:06Z")

</div>

Hi,

I am trying to add day(s) to a date in logstash, based on a filebeat prospector configuration, but when I try adding, I get an error like this:

```auto
[2019-03-31T16:43:14,624][ERROR][logstash.filters.ruby] Ruby exception occurred: no implicit conversion of Fixnum into String

```

Here is the code:

```auto
mutate { add_field => { "[@metadata][record_date]" => "%{@timestamp}" } }
date {
	match => ["[@metadata][record_date]", "YYYY-MM-dd HH:mm:ss,SSS" ]
	target => "[@metadata][record_date]"
}

mutate { add_tag => ["debug_tag_before_inside_if_pruning_frequency_12"] }
	mutate { add_field => { "[@metadata][date_format]" => "%Y.%m.%d" } }

# Set expiration date based on the provided retention value (if not provided, assume the default value)
ruby {
	code => "
		event.set('[@metadata][expiry_index]', (event.get('[@metadata][record_date]') + (86400 * (event.get('retention')))).strftime(event.get('[@metadata][date_format]')));
	"
}

```

I broke down the ruby code, and the error happens when trying to add the 86400 \* the number of days to the date. Here are the values for the fields:

```auto
"@metadata" => {
    "record_date" => "2019-03-31T20:43:07.227Z",
    "date_format" => "%Y.%m.%d",
},
"retention" => 15

```

Any help will be very appreciated.

Thanks,  
Rob

---

<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:** [March 31, 2019, 10:29pm UTC](https://discuss.elastic.co/t/no-implicit-conversion-of-fixnum-into-string-when-adding-days-to-a-date/174690/2 "2019-03-31T22:29:44Z")

</div>

You should also see this in your metadata.

```
 "@metadata" => {
    "record_date" => "2019-03-31T22:26:50.650Z",

```

That does not match the pattern you are using in your date filter. Change that to

```
match => ["[@metadata][record_date]", "ISO8601" ]

```

you will then no longer get the \_dateparsefailure, and out pops

```
 "@metadata" => {
     "record_date" => 2019-03-31T22:27:50.654Z,
    "expiry_index" => "2019.04.15",
     "date_format" => "%Y.%m.%d"
},
```

---

<div class="post-metadata">

**Author:** ![roblopes](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@roblopes](https://discuss.elastic.co/u/roblopes)\
**Post date:** [April 1, 2019, 12:41pm UTC](https://discuss.elastic.co/t/no-implicit-conversion-of-fixnum-into-string-when-adding-days-to-a-date/174690/3 "2019-04-01T12:41:35Z")

</div>

> [@Badger](#):
>
> ISO8601

@Badger, you made it. Thanks a lot!

Regards,  
Rob

---

<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:** [April 29, 2019, 12:47pm UTC](https://discuss.elastic.co/t/no-implicit-conversion-of-fixnum-into-string-when-adding-days-to-a-date/174690/4 "2019-04-29T12:47:54Z")

</div>

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