<?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: Unable to calculate a difference after using mvindex with _time field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432880#M123676</link>
    <description>&lt;P&gt;Are you sure that you are ending up with a multi-value field called myTime? Can you post sample data, anonymized if necessary?&lt;/P&gt;</description>
    <pubDate>Mon, 05 Aug 2019 18:28:26 GMT</pubDate>
    <dc:creator>grittonc</dc:creator>
    <dc:date>2019-08-05T18:28:26Z</dc:date>
    <item>
      <title>Unable to calculate a difference after using mvindex with _time field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432879#M123675</link>
      <description>&lt;P&gt;I am using a transaction to combine events and I want to calculate the difference in time between the two events. I am getting a "Typechecking failed. '-' only takes numbers" error when trying to do subtraction on the _time field. Is there a way to do this? &lt;BR /&gt;
Here is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"Starting task" OR "Terminating task"
| eval myTime = _time 
| transaction pid 
| eval duration = mvindex(myTime, 1)-mvindex(myTime, 0), startTime = strftime(mvindex(myTime, 0), "%m/%d/%Y %H:%M:%S"), endTime = strftime(mvindex(myTime, 1), "%m/%d/%Y %H:%M:%S") 
| table pid startTime endTime duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;*&lt;EM&gt;**Edit&lt;/EM&gt;*&lt;BR /&gt;
Responding to grittonc's question:&lt;BR /&gt;
Yes - I am certain myTime is multi-valued. I can properly see the startTime and endTime values populating correctly in my table. Also - here is a snippet of the combined event:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/7466i3364EB4DCAD913CF/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 17:38:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432879#M123675</guid>
      <dc:creator>tewarbit</dc:creator>
      <dc:date>2019-08-05T17:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to calculate a difference after using mvindex with _time field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432880#M123676</link>
      <description>&lt;P&gt;Are you sure that you are ending up with a multi-value field called myTime? Can you post sample data, anonymized if necessary?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 18:28:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432880#M123676</guid>
      <dc:creator>grittonc</dc:creator>
      <dc:date>2019-08-05T18:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to calculate a difference after using mvindex with _time field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432881#M123677</link>
      <description>&lt;P&gt;You either need to calculate the epoch time start and end first, or add &lt;CODE&gt;tonumber()&lt;/CODE&gt; to convert them to numbers:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval end=mvindex(myTime, 1), start=mvindex(myTime, 0), duration = end-start&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;|eval duration=tonumber(mvindex(myTime, 1))-tonumber(mvindex(myTime, 0))&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 19:11:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432881#M123677</guid>
      <dc:creator>grittonc</dc:creator>
      <dc:date>2019-08-05T19:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to calculate a difference after using mvindex with _time field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432882#M123678</link>
      <description>&lt;P&gt;Both ways worked perfectly. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 19:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Unable-to-calculate-a-difference-after-using-mvindex-with-time/m-p/432882#M123678</guid>
      <dc:creator>tewarbit</dc:creator>
      <dc:date>2019-08-05T19:20:44Z</dc:date>
    </item>
  </channel>
</rss>

