# Ruby exception occurred: invalid date when passing date from logstash to ruby

**URL:** <https://discuss.elastic.co/t/ruby-exception-occurred-invalid-date-when-passing-date-from-logstash-to-ruby/200689>\
**Category:** Logstash\
**Created:** [September 23, 2019, 12:08pm UTC](https://discuss.elastic.co/t/ruby-exception-occurred-invalid-date-when-passing-date-from-logstash-to-ruby/200689 "2019-09-23T12:08:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kolli\_dilip](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kolli_dilip/32/33821_2.png) [@kolli\_dilip](https://discuss.elastic.co/u/kolli_dilip)\
**Post date:** [September 23, 2019, 12:08pm UTC](https://discuss.elastic.co/t/ruby-exception-occurred-invalid-date-when-passing-date-from-logstash-to-ruby/200689/1 "2019-09-23T12:08:14Z")

</div>

Hi All,

Have a sample set of data as below

> ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/0/90fc01a386f7130baecae900adcd18e4bb16cfe4.png)

> orders type createdon dispatchedon deliveredon  
> C015 2 31/07/2019 18:09 31/07/2019 18:15 11/09/2019 16:28  
> C018 3 06/08/2019 11:46 11/09/2019 12:24 11/09/2019 12:26  
> C019 4 08/08/2019 13:59 08/08/2019 17:57 11/09/2019 17:58  
> C020 3 13/08/2019 12:20 13/08/2019 12:50 11/09/2019 16:27

i was working on calculation of time difference based on createdon time as on colum3..

my logstash config is as below

> input  
> {  
> file  
> {  
> path =\> "F:/nana/\*.csv"  
> start\_position =\> "beginning"  
> codec =\> plain {charset =\> "ISO-8859-1" }  
> }  
> }  
> filter  
> {  
> csv  
> {  
> separator =\> ","  
> columns =\> ["orders","type","createdon","dispatchedon","deliveredon"]  
> skip\_header =\> true  
> }  
> ruby  
> {   
> init =\> "require 'date'"  
> code =\> '  
> createddayhours = 0  
> t\_created = event.get("createdon")  
> t\_created = DateTime.parse("t\_created")  
> created\_hour= t\_created.hour  
> created\_min =t\_created.min  
> createdday\_lastworkinghour =(DateTime.parse("%F 18:00"))  
> createddayhours = (((createdday\_lastworkinghour-t\_created)/60)/60).to\_f  
> if createddayhours \> 0 and createddayhours \< 10  
> createddayhours = createddayhours  
> elsif createddayhours \< 0  
> createddayhours = 0  
> else  
> createddayhours = 0  
> end  
> event.set("createddayhours", createddayhours)  
> '  
> }   
> }  
> output {  
> stdout{}  
> elasticsearch  
> {  
> hosts =\> "[http://localhost](http://localhost):port"  
> index =\> "sample"  
> }   
> }

there is a ruby exception coming up as below

> [2019-09-23T12:51:25,309][ERROR][logstash.filters.ruby] Ruby exception occurred: invalid date  
> [2019-09-23T12:51:25,309][ERROR][logstash.filters.ruby] Ruby exception occurred: invalid date  
> [2019-09-23T12:51:25,309][ERROR][logstash.filters.ruby] Ruby exception occurred: invalid date

can some one help me on this

Thanks

---

<div class="post-metadata">

**Author:** ![kolli\_dilip](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kolli_dilip/32/33821_2.png) [@kolli\_dilip](https://discuss.elastic.co/u/kolli_dilip)\
**Post date:** [September 25, 2019, 2:27am UTC](https://discuss.elastic.co/t/ruby-exception-occurred-invalid-date-when-passing-date-from-logstash-to-ruby/200689/2 "2019-09-25T02:27:53Z")

</div>

> [@kolli\_dilip](#):
>
> t\_created = event.get("createdon")  
> t\_created = DateTime.parse("t\_created")

t\_created = event.get("createdon").to\_s worked 🙂

---

<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:** [October 23, 2019, 2:27am UTC](https://discuss.elastic.co/t/ruby-exception-occurred-invalid-date-when-passing-date-from-logstash-to-ruby/200689/3 "2019-10-23T02:27:57Z")

</div>

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