<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Compute time difference between events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295199#M174713</link>
    <description>&lt;P&gt;So I basically did this and got what I wanted:&lt;/P&gt;

&lt;P&gt;transaction host startswith="Launch" endswith="Open" | streamstats sum(TimeSec) as dur window=1 |&lt;/P&gt;

&lt;P&gt;Thank you for your support. I had been such  a stupid to not observe this earlier.&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2017 13:50:43 GMT</pubDate>
    <dc:creator>pranaynanda</dc:creator>
    <dc:date>2017-05-18T13:50:43Z</dc:date>
    <item>
      <title>Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295185#M174699</link>
      <description>&lt;P&gt;I have events like&lt;/P&gt;

&lt;P&gt;Event                 EndDateTime&lt;BR /&gt;
Launch              2017-05-16 13:00:00&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
Open        2017-05-16 13:00:30&lt;/P&gt;

&lt;P&gt;I want to subtract time between these two events. &lt;/P&gt;

&lt;P&gt;I want to implement something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myindex" sourcetype="mysourcetype"  | transaction host startswith="Launch" endswith="Open"|convert timeformat="%Y-%m-%d %H:%M:%S" mktime(EndDateTime)| eval difference=[subtract EndDateTime where Event=Open - EndDateTime where Event=Launch| chart  avg(difference) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I just can't understand how can I work with the eval part about calculating difference. &lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 07:44:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295185#M174699</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-16T07:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295186#M174700</link>
      <description>&lt;P&gt;The transaction command should already be giving you duration field, and it would be correct as long as your _time field was extracted based of values of EndDateTime field (both _time and EndDateTime values are same).&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 18:20:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295186#M174700</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-05-16T18:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295187#M174701</link>
      <description>&lt;P&gt;looks like you are looking for the duration between events &lt;BR /&gt;
the "duration" field is extracted with the transaction command&lt;BR /&gt;
you can just | table duration after your transaction command and you can see the "difference in time"&lt;BR /&gt;
hope i understand your question correctly&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 18:21:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295187#M174701</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2017-05-16T18:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295188#M174702</link>
      <description>&lt;P&gt;That's the thing. They are not.&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 06:39:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295188#M174702</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-17T06:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295189#M174703</link>
      <description>&lt;P&gt;The _time and EndDateTime values are not same. duration won't work in that case. Also, I did try what you're telling before posting this question and there were differences in answers which makes sense as _time did not add the time taken by last event in duration.&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 06:40:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295189#M174703</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-17T06:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295190#M174704</link>
      <description>&lt;P&gt;You can try creating a TRANID manually and get the difference -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myindex" sourcetype="mysourcetype" "Launch" OR "Open" | eval TRANID=if(like(EVENT,"%Launch%"),1,0) | streamstats sum(TRANID) as TRANID | convert timeformat="%Y-%m-%d %H:%M:%S" mktime(EndDateTime) | eval start_time=if(like(EVENT,"%Launch%"),EndDateTime,0)  | eval end_time=if(like(EVENT,"%Open%"),EndDateTime,0) | stats sum(start_time) as start_time,sum(end_time) as end_time by TRANID | eval diff=end_time=start_time 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 May 2017 07:50:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295190#M174704</guid>
      <dc:creator>dineshraj9</dc:creator>
      <dc:date>2017-05-17T07:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295191#M174705</link>
      <description>&lt;P&gt;Did not work! &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;It says: Error in 'eval' command: Fields cannot be assigned a boolean result. Instead, try if([bool expr], [expr], [expr]). &lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 10:07:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295191#M174705</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-18T10:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295192#M174706</link>
      <description>&lt;P&gt;My bad, in the last eval mistakenly gave "=" instead of "-"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="myindex" sourcetype="mysourcetype" "Launch" OR "Open" | eval TRANID=if(like(EVENT,"%Launch%"),1,0) | streamstats sum(TRANID) as TRANID | convert timeformat="%Y-%m-%d %H:%M:%S" mktime(EndDateTime) | eval start_time=if(like(EVENT,"%Launch%"),EndDateTime,0)  | eval end_time=if(like(EVENT,"%Open%"),EndDateTime,0) | stats list(EVENT) as EVENTS,sum(start_time) as start_time,sum(end_time) as end_time by TRANID | eval diff=end_time-start_time 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2017 10:23:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295192#M174706</guid>
      <dc:creator>dineshraj9</dc:creator>
      <dc:date>2017-05-18T10:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295193#M174707</link>
      <description>&lt;P&gt;It only returns all values TRANID, start_time, end_time and diff as '0'&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:07:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295193#M174707</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2020-09-29T14:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295194#M174708</link>
      <description>&lt;P&gt;Can you provide few sample data for a single transaction?&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 10:42:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295194#M174708</guid>
      <dc:creator>dineshraj9</dc:creator>
      <dc:date>2017-05-18T10:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295195#M174709</link>
      <description>&lt;H2&gt;Test Name Start Date Start Time Time Interval Stop Date/Time Start Time(ms) Stop Time(ms) Run Time(min) Run Time(sec) Run Time(ms)&lt;/H2&gt;

&lt;P&gt;Launch  5/18/2017   14:00:37    14  5/18/2017 14:01 2.98235E+11 2.98331E+11 0.51    30.87   30865.67&lt;BR /&gt;
Login   5/18/2017   14:01:34    14  5/18/2017 14:03 2.98401E+11 2.98741E+11 1.74    104.41  104412.77&lt;BR /&gt;
Search  5/18/2017   14:04:08    14  5/18/2017 14:04 2.98854E+11 2.98884E+11 0.17    10.24   10244.62&lt;BR /&gt;
CheckOut    5/18/2017   14:04:48    14  5/18/2017 14:04 2.98969E+11 2.98977E+11 0.05    2.71    2713.89&lt;BR /&gt;
Expand  5/18/2017   14:06:47    14  5/18/2017 14:07 2.99316E+11 2.99476E+11 0.92    54.97   54971.75&lt;BR /&gt;
LaunchApp   5/18/2017   14:08:36    14  5/18/2017 14:20 2.99636E+11 3.01742E+11 12.01   720.87  720872.82&lt;BR /&gt;
Open    5/18/2017   14:21:32    14  5/18/2017 14:31 3.01903E+11 3.03665E+11 10.05   603.24  603235.27&lt;/P&gt;

&lt;P&gt;The Stop Date/Time column is extracted in Splunk as EndDateTime.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 11:06:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295195#M174709</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-18T11:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295196#M174710</link>
      <description>&lt;P&gt;I tested with your data this way and it is working for me this way -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  basesearch  | rename "Stop Date/Time" as EndDateTime,"Test Name" as EVENT | eval EndDateTime=round(strptime(EndDateTime,"%m/%d/%Y %H:%M")) | eval TRANID=if(like(EVENT,"Launch"),1,0) | streamstats sum(TRANID) as TRANID | convert timeformat="%Y-%m-%d %H:%M:%S" mktime(EndDateTime) | eval start_time=if(like(EVENT,"Launch"),EndDateTime,0)  | eval end_time=if(like(EVENT,"Open"),EndDateTime,0) | stats list(EVENT) as EVENTS,sum(start_time) as start_time,sum(end_time) as end_time by TRANID | eval diff=end_time-start_time 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2017 12:03:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295196#M174710</guid>
      <dc:creator>dineshraj9</dc:creator>
      <dc:date>2017-05-18T12:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295197#M174711</link>
      <description>&lt;P&gt;Thanks for your support. I just relaized that when I have the RunTime in seconds for each event, I can also get a sum of all of them by each Transaction. The thing is that sum(TimeSec) add all of them where I want it by transaction.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 13:18:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295197#M174711</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-18T13:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295198#M174712</link>
      <description>&lt;P&gt;O I basically did this and got what I wanted:&lt;/P&gt;

&lt;P&gt;transaction host startswith="Launch" endswith="Open" | streamstats sum(TimeSec) as dur window=1 |&lt;/P&gt;

&lt;P&gt;Thank you for your support. I had been such  a stupid to not observe this earlier.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 13:50:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295198#M174712</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-18T13:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295199#M174713</link>
      <description>&lt;P&gt;So I basically did this and got what I wanted:&lt;/P&gt;

&lt;P&gt;transaction host startswith="Launch" endswith="Open" | streamstats sum(TimeSec) as dur window=1 |&lt;/P&gt;

&lt;P&gt;Thank you for your support. I had been such  a stupid to not observe this earlier.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 13:50:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295199#M174713</guid>
      <dc:creator>pranaynanda</dc:creator>
      <dc:date>2017-05-18T13:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Compute time difference between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295200#M174714</link>
      <description>&lt;P&gt;@pranaynanda - I've converted your comment to an answer.  Thanks for posting it.  &lt;/P&gt;

&lt;P&gt;Please accept your answer so the question will show as closed.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 14:34:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-time-difference-between-events/m-p/295200#M174714</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-18T14:34:38Z</dc:date>
    </item>
  </channel>
</rss>

