# How calculate time différence between two rows in csv file?

**URL:** <https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192>\
**Category:** Logstash\
**Created:** [April 28, 2020, 2:06pm UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192 "2020-04-28T14:06:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [April 28, 2020, 2:06pm UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192/1 "2020-04-28T14:06:28Z")

</div>

Hi, Please i need to calculate différence of time between two rows in my file

> My csv file it looks like this  
> ent\_sort , Date , car  
> enter, 2020-04-28 05:04:02 , c1  
> sortie , 2020-04-28 10:04:02 , c1  
> enter , 2020-04-28 05:04:02 , c3  
> sortie , 2020-04-28 10:04:02 , c2  
> enter , 2020-04-28 05:04:02 , c2  
> sortie , 2020-04-28 12:04:02 , c3

> Blockquote

So i want calculate for c1 time différence and for c2 .....please any help?

---

<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:** [April 28, 2020, 4:45pm UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192/2 "2020-04-28T16:45:42Z")

</div>

Use an aggregate filter (see example 5) or an elapsed filter.

Make sure to set pipeline.workers to 1 and [disable java\_execution](https://github.com/elastic/logstash/issues/10938).

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [April 29, 2020, 8:00am UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192/3 "2020-04-29T08:00:42Z")

</div>

Hi, i try elapsed filter and i add this two line in logstash.yml

> Blockquote  
> elapsed {  
> start\_tag =\> "taskStarted"  
> end\_tag =\> "taskEnded"  
> add\_tag =\> ["time\_elapsed"]  
> }

> Blockquote  
> pipeline.workers: 1  
> pipeline.java\_execution: false

> Blockquote  
> but i have no result the time différence not exist

---

<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:** [April 29, 2020, 1:13pm UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192/4 "2020-04-29T13:13:11Z")

</div>

How did you add the taskStarted and taskEnded tags to the events? Something like this?...

```
if [ent_sort] == "sortie" { mutate { add_tag => ["taskEnded"] } }
```

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [April 29, 2020, 1:56pm UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192/5 "2020-04-29T13:56:15Z")

</div>

I did this code

> Blockquote  
> if [ent\_sortie] == "sortie" { mutate { add\_tag =\> ["taskEnded"] } }  
> else if [ent\_sort] == "enter" { mutate { add\_tag =\> ["taskStarted"] } }  
> elapsed {  
> unique\_id\_field =\> "Car"  
> start\_tag =\> "taskStarted"  
> end\_tag =\> "taskEnded"  
> add\_tag =\> ["time\_elapsed"]  
> }

> Blockquote

the output in console

> Blockquote  
> ........  
> "tags" =\> [  
> [0] "taskEnded",  
> [1] "time\_elapsed",  
> [2] "elapsed\_end\_without\_start"

---

<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:** [April 29, 2020, 2:14pm UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192/6 "2020-04-29T14:14:12Z")

</div>

> [@Emna1](#):
>
> if [ent\_sortie] == "sortie" { mutate { add\_tag =\> ["taskEnded"] } }  
> else if [ent\_sort] == "enter" ...

That's checking the value of two different fields.

---

<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:** [May 27, 2020, 4:54pm UTC](https://discuss.elastic.co/t/how-calculate-time-difference-between-two-rows-in-csv-file/230192/9 "2020-05-27T16:54:42Z")

</div>

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