<?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 How Calculate the difference between two time fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257227#M77025</link>
    <description>&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/118187-img.png" alt="alt text" /&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I am trying to calculate the difference between two time fields.Below is the query which I ran to get the output .i have done mvexpand on three fields ENDPOINT_LOG{}.EML_REQUEST_TIME,ENDPOINT_LOG{}.EML_RESPONSE_TIME,ENDPOINT_LOG{}.EML_REQ_CONN_URI since there are two fields in a single event.&lt;/P&gt;

&lt;P&gt;index=test  | mvexpand  ENDPOINT_LOG{}.EML_REQUEST_TIME|mvexpand ENDPOINT_LOG{}.EML_RESPONSE_TIME |mvexpand ENDPOINT_LOG{}.EML_REQ_CONN_URI | eval req_time=strptime("(ENDPOINT_LOG{}.EML_REQUEST_TIME)","%Y-%m-%d %H:%M:%S.%3N") | eval res_time=strptime("(ENDPOINT_LOG{}.EML_RESPONSE_TIME)","%Y-%m-%d %H:%M:%S.%3N") | eval TimeDiff=res_time-req_time |table TimeDiff, ENDPOINT_LOG{}.EML_REQUEST_TIME,ENDPOINT_LOG{}.EML_RESPONSE_TIME,ENDPOINT_LOG{}.EML_REQ_CONN_URI&lt;/P&gt;

&lt;P&gt;output&lt;/P&gt;

&lt;P&gt;ENDPOINT_LOG{}.EML_REQUEST_TIME     ENDPOINT_LOG{}.EML_RESPONSE_TIME    ENDPOINT_LOG{}.EML_REQ_CONN_URI     time_diff&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_DB2&lt;BR /&gt;&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_PB1&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_DB2&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_PB1&lt;BR /&gt;
 2016-01-19 15:44:01.163 +00:00     2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_DB2&lt;/P&gt;

&lt;P&gt;I want to calculate the time difference of ENDPOINT_LOG{}.EML_RESPONSE_TIME from&lt;BR /&gt;
ENDPOINT_LOG{}.EML_REQUEST_TIME and store in time_diff &lt;/P&gt;

&lt;P&gt;but when I ran the query the time_diff is having all null ,the eval command is not executing and storing result in time_diff&lt;/P&gt;

&lt;P&gt;Can anyone please help in this&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 09:10:06 GMT</pubDate>
    <dc:creator>vrmandadi</dc:creator>
    <dc:date>2020-09-29T09:10:06Z</dc:date>
    <item>
      <title>How Calculate the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257227#M77025</link>
      <description>&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/118187-img.png" alt="alt text" /&gt;Hello all,&lt;/P&gt;

&lt;P&gt;I am trying to calculate the difference between two time fields.Below is the query which I ran to get the output .i have done mvexpand on three fields ENDPOINT_LOG{}.EML_REQUEST_TIME,ENDPOINT_LOG{}.EML_RESPONSE_TIME,ENDPOINT_LOG{}.EML_REQ_CONN_URI since there are two fields in a single event.&lt;/P&gt;

&lt;P&gt;index=test  | mvexpand  ENDPOINT_LOG{}.EML_REQUEST_TIME|mvexpand ENDPOINT_LOG{}.EML_RESPONSE_TIME |mvexpand ENDPOINT_LOG{}.EML_REQ_CONN_URI | eval req_time=strptime("(ENDPOINT_LOG{}.EML_REQUEST_TIME)","%Y-%m-%d %H:%M:%S.%3N") | eval res_time=strptime("(ENDPOINT_LOG{}.EML_RESPONSE_TIME)","%Y-%m-%d %H:%M:%S.%3N") | eval TimeDiff=res_time-req_time |table TimeDiff, ENDPOINT_LOG{}.EML_REQUEST_TIME,ENDPOINT_LOG{}.EML_RESPONSE_TIME,ENDPOINT_LOG{}.EML_REQ_CONN_URI&lt;/P&gt;

&lt;P&gt;output&lt;/P&gt;

&lt;P&gt;ENDPOINT_LOG{}.EML_REQUEST_TIME     ENDPOINT_LOG{}.EML_RESPONSE_TIME    ENDPOINT_LOG{}.EML_REQ_CONN_URI     time_diff&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_DB2&lt;BR /&gt;&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_PB1&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_DB2&lt;BR /&gt;
2016-01-19 15:44:00.749 +00:00  2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_PB1&lt;BR /&gt;
 2016-01-19 15:44:01.163 +00:00     2016-01-19 15:44:02.366 +00:00  connection:/s4970qalv/DCD_DB2&lt;/P&gt;

&lt;P&gt;I want to calculate the time difference of ENDPOINT_LOG{}.EML_RESPONSE_TIME from&lt;BR /&gt;
ENDPOINT_LOG{}.EML_REQUEST_TIME and store in time_diff &lt;/P&gt;

&lt;P&gt;but when I ran the query the time_diff is having all null ,the eval command is not executing and storing result in time_diff&lt;/P&gt;

&lt;P&gt;Can anyone please help in this&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:10:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257227#M77025</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2020-09-29T09:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: How Calculate the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257228#M77026</link>
      <description>&lt;P&gt;In order to use field names with special characters such as a dot in &lt;CODE&gt;eval&lt;/CODE&gt; you have to enclose them in single quotes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval req_time = strptime('ENDPOINT_LOG{}.EML_REQUEST_TIME', "%Y-%m-%d %H:%M:%S.%3N") | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Check that each time field is filled with an epoch timestamp before proceeding.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 21:47:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257228#M77026</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-03-22T21:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: How Calculate the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257229#M77027</link>
      <description>&lt;P&gt;Thank You so much martin_muller.&lt;/P&gt;

&lt;P&gt;One small question ,I got the timediff for each and every request and response but i want to calculate the average of timediff &lt;/P&gt;

&lt;P&gt;I ran the query &lt;/P&gt;

&lt;P&gt;|stats avg(timediff) which is giving me a wrong value &lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 22:13:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257229#M77027</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2016-03-22T22:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: How Calculate the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257230#M77028</link>
      <description>&lt;P&gt;That would be the correct approach, in what way is the returned value wrong?&lt;/P&gt;

&lt;P&gt;Keep in mind to stick with a field name, I've seen &lt;CODE&gt;time_diff&lt;/CODE&gt;, &lt;CODE&gt;timediff&lt;/CODE&gt;, and &lt;CODE&gt;TimeDiff&lt;/CODE&gt; in your posts.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 22:29:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257230#M77028</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-03-22T22:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: How Calculate the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257231#M77029</link>
      <description>&lt;P&gt;ya,I used TimeDiff,but I think since I used three mvexpand the events are duplicated and strangely some fields have TimeDiff with negative values ,but when looked into that particular event the difference between request and response time is not negative.I dont know how splunk populated new request and response times&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 23:08:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257231#M77029</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2016-03-22T23:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: How Calculate the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257232#M77030</link>
      <description>&lt;P&gt;If you have two arrays of values and expand each array into individual events, you will then calculate an &lt;CODE&gt;n*m&lt;/CODE&gt; matrix of differences, not the probably intended &lt;CODE&gt;a1-b1, a2-b2, ...&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I'd guess you need to &lt;CODE&gt;mvexpand&lt;/CODE&gt; once on &lt;CODE&gt;ENDPOINT_LOG{}&lt;/CODE&gt; to keep matching pairs together, but without knowing the data that's just that - a guess.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 23:19:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257232#M77030</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-03-22T23:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: How Calculate the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257233#M77031</link>
      <description>&lt;P&gt;I have updated an image along with the query,so that you have a better idea of the query,I want the timediff for each uri for its corresponding request and reponse time&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 23:38:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-Calculate-the-difference-between-two-time-fields/m-p/257233#M77031</guid>
      <dc:creator>vrmandadi</dc:creator>
      <dc:date>2016-03-22T23:38:05Z</dc:date>
    </item>
  </channel>
</rss>

