# Math & date: ruby & logstash

**URL:** https://discuss.elastic.co/t/math-date-ruby-logstash/45945
**Category:** Logstash
**Created:** [March 31, 2016, 1:33pm UTC](https://discuss.elastic.co/t/math-date-ruby-logstash/45945 "2016-03-31T13:33:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![garanews](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@garanews](https://discuss.elastic.co/u/garanews)
#### Post date: [March 31, 2016, 1:33pm UTC](https://discuss.elastic.co/t/math-date-ruby-logstash/45945/1 "2016-03-31T13:33:11Z")

</div>

Hello,  
I have some log files that have rows like this:

station1 on 15387 15646 130 Y

Values are separated by tab

With logstash I would transform the first\_seen and last\_seen in timestamp, because they are the number of days after 1/1/1970  
So basically I should just multiply by 86400 to have seconds and then use the logstash date funcion.  
The code below is not doing what I am expecting

```
                    if [type] == "test_log" {

             csv {
                            separator => " "
                            columns => ["client", "status", "first_seen", "last_seen", "times_seen", valid"]
                            }

```

if [first\_seen] != "-" {  
ruby  
{ code =\> "event['first\_seen'] = event['first\_seen'].to\_f \* 86400"}  
date {  
match =\> ["first\_seen", "UNIX"]  
}  
}

if [ast\_seen] != "-" {  
ruby  
{ code =\> "event['last\_seen'] = event['last\_seen'].to\_f \* 86400"}  
date {  
match =\> ["last\_seen", "UNIX"]  
}  
}

It seems that out of ruby code the variable is not set and in the logstash.log I have errors like "the - is not valid unix time" repeated for milion of times.

Can you please give me an hint?  
Thanks in advance

---

<div class="post-metadata">

### Author: ![kirill\_polishchuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kirill_polishchuk/32/6489_2.png) [@kirill\_polishchuk](https://discuss.elastic.co/u/kirill_polishchuk)
#### Post date: [March 31, 2016, 5:09pm UTC](https://discuss.elastic.co/t/math-date-ruby-logstash/45945/2 "2016-03-31T17:09:35Z")

</div>

You should try convert to integer, instead of to float:  
ruby  
{ code =\> "event['last\_seen'] = event['last\_seen'].to\_i\* 86400"}

when float you are getting epoch date like: `1329436800.0` ( epoch date with comma - is not well formatted date)

---

<div class="post-metadata">

### Author: ![garanews](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@garanews](https://discuss.elastic.co/u/garanews)
#### Post date: [April 1, 2016, 10:28am UTC](https://discuss.elastic.co/t/math-date-ruby-logstash/45945/3 "2016-04-01T10:28:03Z")

</div>

I did but nothing changed...

---

<div class="post-metadata">

### Author: ![garanews](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@garanews](https://discuss.elastic.co/u/garanews)
#### Post date: [April 8, 2016, 7:05am UTC](https://discuss.elastic.co/t/math-date-ruby-logstash/45945/4 "2016-04-08T07:05:00Z")

</div>

any other suggestion?  
Thanks

---

<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 6, 2017, 5:03am UTC](https://discuss.elastic.co/t/math-date-ruby-logstash/45945/5 "2017-07-06T05:03:09Z")

</div>


