# Ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:35.919"

**URL:** <https://discuss.elastic.co/t/ruby-ruby-exception-occurred-invalid-date-2019-04-18-0635-919/183044>\
**Category:** Logstash\
**Created:** [May 28, 2019, 9:31am UTC](https://discuss.elastic.co/t/ruby-ruby-exception-occurred-invalid-date-2019-04-18-0635-919/183044 "2019-05-28T09:31:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yoav\_Ben\_Moha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yoav_ben_moha/32/46202_2.png) [@Yoav\_Ben\_Moha](https://discuss.elastic.co/u/Yoav_Ben_Moha)\
**Post date:** [May 28, 2019, 9:31am UTC](https://discuss.elastic.co/t/ruby-ruby-exception-occurred-invalid-date-2019-04-18-0635-919/183044/1 "2019-05-28T09:31:14Z")

</div>

I am trying to find a diff betweentwo dates.  
I have wrote the following con file which use Ruby in order to caculate the date diff.  
I recived : ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:35.919"

The conf file:  
input {  
file {  
path =\> "/home/logstash/cdr\_files/top10.csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}

```
filter {
        csv {
             separator => ","
           columns => [
                       "P9","P11","P21","P30"
                      ]
             }

        mutate { rename => { "P9" => "CALLING_NUMBER" } }
        mutate { rename => { "P11" => "CALLED_NUMBER" } }
        mutate { rename => { "P21" => "ING_SIGNAL_START_TIME" } }
        mutate { rename => { "P30" => "ING_CALL_ANSWER_TIME" } }

        date {
                match => ["P21", "YYYY-MM-dd'+'HH:mm:ss.SSS"]
                target => ["ING_SIGNAL_START_TIME"]
                remove_field => ["P21"]
              }

        date {
                match => ["P30", "YYYY-MM-dd'+'HH:mm:ss.SSS"]
                target => ["ING_CALL_ANSWER_TIME"]
                remove_field => ["P30"]
              }

ruby {
    init => "require 'time'"
    code => "
           starttime = Time.iso8601(event.get('ING_SIGNAL_START_TIME').to_s).to_f;
           endtime = Time.iso8601(event.get('ING_ADDRESS_COMPLETE_TIME').to_s).to_f;
           event.set('time_diff', endtime - starttime);
            "
    add_tag => ["ING_SST_MINUS_ING_ACT_CALCUALTED"]
}

}

output {
        elasticsearch {
                        hosts => "localhost"
                        index => "top10"
                        document_type => "quick_log"
                      }
        stdout {}

```

The error

> ```
> [INFO] 2019-05-28 12:24:10.754 [[main]<file] observingtail - START, creating Discoverer, Watch with file and sincedb collections
> [INFO] 2019-05-28 12:24:11.498 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600}
> [ERROR] 2019-05-28 12:24:12.844 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:35.919"
> [ERROR] 2019-05-28 12:24:12.849 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:10.946"
> [ERROR] 2019-05-28 12:24:12.850 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:39.416"
> [ERROR] 2019-05-28 12:24:12.850 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:36.915"
> [ERROR] 2019-05-28 12:24:12.851 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:38.636"
> [ERROR] 2019-05-28 12:24:12.851 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:22:58.574"
> [ERROR] 2019-05-28 12:24:12.851 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:20:24.000"
> [ERROR] 2019-05-28 12:24:12.852 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:00.175"
> [ERROR] 2019-05-28 12:24:12.852 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:38.324"
> [ERROR] 2019-05-28 12:24:12.853 [[main]>worker1] ruby - Ruby exception occurred: invalid date: "2019-04-18+06:23:40.887"
> /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/awesome_print-1.7.0/lib/awesome_print/formatters/base_formatter.rb:31: warning: constant ::Fixnum is deprecated
> {
> "ING_CALL_ANSWER_TIME" => nil,
> "tags" => [
> [0] "_rubyexception"
> ],
> "CALLED_NUMBER" => "8656",
> "message" => "1679,8656,2019-04-18+06:23:35.919,\r",
> "ING_SIGNAL_START_TIME" => "2019-04-18+06:23:35.919",
> "@version" => "1",
> "CALLING_NUMBER" => "1679",
> "host" => "elk7-lab",
> "@timestamp" => 2019-05-28T09:24:12.171Z,
> "path" => "/home/logstash/cdr_files/top10.csv"
> }
> {
> "ING_CALL_ANSWER_TIME" => nil,
> "tags" => [
> [0] "_rubyexception"
> ],
> "CALLED_NUMBER" => "0878",
> "message" => "9.23E+11,0878,2019-04-18+06:23:10.946,\r",
> "ING_SIGNAL_START_TIME" => "2019-04-18+06:23:10.946",
> "@version" => "1",
> "CALLING_NUMBER" => "9.23E+11",
> "host" => "elk7-lab",
> "@timestamp" => 2019-05-28T09:24:12.217Z,
> "path" => "/home/logstash/cdr_files/top10.csv"
> 
> ```

Please advise whats wrong

Thanks Alot

---

<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:** [May 28, 2019, 1:48pm UTC](https://discuss.elastic.co/t/ruby-ruby-exception-occurred-invalid-date-2019-04-18-0635-919/183044/2 "2019-05-28T13:48:44Z")

</div>

You rename P21 and P30, then after that you try to parse those fields, which no longer exist. And the ruby filter references a non-existant ING\_ADDRESS\_COMPLETE\_TIME field. How about

```
ruby {
    init => "require 'time'"
    code => "
       starttime = event.get('ING_SIGNAL_START_TIME').to_f;
       endtime = event.get('ING_CALL_ANSWER_TIME').to_f;
       event.set('time_diff', endtime - starttime);
    "
    add_tag => ["ING_SST_MINUS_ING_ACT_CALCUALTED"]
}
```

---

<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:** [June 25, 2019, 1:48pm UTC](https://discuss.elastic.co/t/ruby-ruby-exception-occurred-invalid-date-2019-04-18-0635-919/183044/3 "2019-06-25T13:48:49Z")

</div>

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