<?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 Subtracting two timestamps in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230899#M68487</link>
    <description>&lt;P&gt;Hi Splunkers.&lt;/P&gt;

&lt;P&gt;I have one issue about subtracting two timestamps.&lt;BR /&gt;
I have the following fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;start=20150917 18:28:32.460
end=20150917 18:28:32:500
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;mysearch&amp;gt; |  eval result_field=end-start
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but no lucky.&lt;/P&gt;

&lt;P&gt;I need the output as &lt;STRONG&gt;result_field=00:00:00.040&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;Can you guys help me?&lt;BR /&gt;
Thank you!&lt;BR /&gt;
Best regards.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2015 14:08:17 GMT</pubDate>
    <dc:creator>guimilare</dc:creator>
    <dc:date>2015-09-18T14:08:17Z</dc:date>
    <item>
      <title>Subtracting two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230899#M68487</link>
      <description>&lt;P&gt;Hi Splunkers.&lt;/P&gt;

&lt;P&gt;I have one issue about subtracting two timestamps.&lt;BR /&gt;
I have the following fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;start=20150917 18:28:32.460
end=20150917 18:28:32:500
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;mysearch&amp;gt; |  eval result_field=end-start
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but no lucky.&lt;/P&gt;

&lt;P&gt;I need the output as &lt;STRONG&gt;result_field=00:00:00.040&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;Can you guys help me?&lt;BR /&gt;
Thank you!&lt;BR /&gt;
Best regards.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 14:08:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230899#M68487</guid>
      <dc:creator>guimilare</dc:creator>
      <dc:date>2015-09-18T14:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230900#M68488</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Your search&amp;gt; | eval result_field=tostring(strptime(end,"%Y%m%d %H:%M:%S.%N")-strptime(start,"%Y%m%d %H:%M:%S.%N"),"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Updated per new req&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Your search &amp;gt; | eval result_field=strptime(end,"%Y%m%d %H:%M:%S.%N")-strptime(start,"%Y%m%d %H:%M:%S.%N") | stats avg(result_field) as result_field | eval result_field=tostring(result_field,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2015 14:15:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230900#M68488</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-18T14:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230901#M68489</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;

&lt;P&gt;What you're looking for is a tostring conversion.&lt;/P&gt;

&lt;P&gt;Simply use the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;mysearch&amp;gt; |  eval result_field=end-start | eval result_field = tostring(result_field,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or simply:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;mysearch&amp;gt; |  eval result_field = tostring(end-start,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know how that works out for you!&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 14:19:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230901#M68489</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2015-09-18T14:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230902#M68490</link>
      <description>&lt;P&gt;Hi Somesoni2,&lt;BR /&gt;
this appears to work!&lt;BR /&gt;
How can I get an average from result_field?&lt;BR /&gt;
I tried to do &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;Your search&amp;gt; | eval result_field=tostring(strptime(end,"%Y%m%d %H:%M:%S.%N")-strptime(start,"%Y%m%d %H:%M:%S.%N"),"duration") | avg(result_field) as Average
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but no success.&lt;BR /&gt;
Regards&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 14:41:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230902#M68490</guid>
      <dc:creator>guimilare</dc:creator>
      <dc:date>2015-09-18T14:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230903#M68491</link>
      <description>&lt;P&gt;The above query generates a string field with the format you requested, so can't get the avg. Try the updated query.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 14:55:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230903#M68491</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-18T14:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230904#M68492</link>
      <description>&lt;P&gt;It still not working for .  i have this sample log entry where boot-time for each machine in ENV are reported&lt;BR /&gt;
I have 2016-05,ENV,R1,W,05/25/16 21:00:00.000,05/26/16 02:00:00.000,05/25/16 23:09:00.000,05/26/16 05:12:00.000,183&lt;/P&gt;

&lt;P&gt;Where my "Scheduled End Time"  : 05/26/16 02:00:00.000&lt;BR /&gt;
"Actual End Time" : 05/26/18 05:12:00.000&lt;BR /&gt;
I wanted the difference in minutes between Actual End Time and Scheduled End time.  (192 minutes)&lt;/P&gt;

&lt;P&gt;I have tried this approach &lt;BR /&gt;
{search}|eval ac_end='Actual End Time'|convert mktime(ac_end) as ac_time timeformat="%Y-%m-%d %H:%M:%S" &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:25:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subtracting-two-timestamps/m-p/230904#M68492</guid>
      <dc:creator>sunilsk1</dc:creator>
      <dc:date>2020-09-29T20:25:52Z</dc:date>
    </item>
  </channel>
</rss>

