<?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 Calculating the time difference between fields, how do I properly convert the resulting value to a human readable format? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154381#M43423</link>
    <description>&lt;P&gt;Hi all.&lt;/P&gt;

&lt;P&gt;I have two fields, &lt;CODE&gt;in&lt;/CODE&gt; with values like 2015-08-04 05:52:42 and &lt;CODE&gt;out&lt;/CODE&gt; with values like "2015-08-04 06:18:30" in the same record.&lt;/P&gt;

&lt;P&gt;in = 2015-08-04 05:52:42&lt;BR /&gt;
out = 2015-08-04 06:18:30&lt;/P&gt;

&lt;P&gt;I need to calculate the time difference between out and in. I am using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval comein=strptime(in,"%Y-%m-%d %H:%M:%S") | eval goout=strptime(out,"%Y-%m-%d %H:%M:%S") | eval diff= goout - comein
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a resulting field called diff with the time difference in epoch time (is a relative time like 226.000000).&lt;/P&gt;

&lt;P&gt;I tried to convert this to human readable format using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | convert timeformat="%M:%S" ctime(diff)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But the resulting value doesn't properly convert the quantity in hours, only minutes and secs. Any way to show the difference like 20h,20m,20secs for example? &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 04 Aug 2015 18:21:52 GMT</pubDate>
    <dc:creator>changux</dc:creator>
    <dc:date>2015-08-04T18:21:52Z</dc:date>
    <item>
      <title>Calculating the time difference between fields, how do I properly convert the resulting value to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154381#M43423</link>
      <description>&lt;P&gt;Hi all.&lt;/P&gt;

&lt;P&gt;I have two fields, &lt;CODE&gt;in&lt;/CODE&gt; with values like 2015-08-04 05:52:42 and &lt;CODE&gt;out&lt;/CODE&gt; with values like "2015-08-04 06:18:30" in the same record.&lt;/P&gt;

&lt;P&gt;in = 2015-08-04 05:52:42&lt;BR /&gt;
out = 2015-08-04 06:18:30&lt;/P&gt;

&lt;P&gt;I need to calculate the time difference between out and in. I am using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval comein=strptime(in,"%Y-%m-%d %H:%M:%S") | eval goout=strptime(out,"%Y-%m-%d %H:%M:%S") | eval diff= goout - comein
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a resulting field called diff with the time difference in epoch time (is a relative time like 226.000000).&lt;/P&gt;

&lt;P&gt;I tried to convert this to human readable format using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | convert timeformat="%M:%S" ctime(diff)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But the resulting value doesn't properly convert the quantity in hours, only minutes and secs. Any way to show the difference like 20h,20m,20secs for example? &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2015 18:21:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154381#M43423</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2015-08-04T18:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the time difference between fields, how do I properly convert the resulting value to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154382#M43424</link>
      <description>&lt;P&gt;Hi @changux&lt;/P&gt;

&lt;P&gt;I think you forgot the %H in your timeformat conversion. so it should be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | convert timeformat="%H:%M:%S" ctime(diff)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2015 18:37:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154382#M43424</guid>
      <dc:creator>ppablo</dc:creator>
      <dc:date>2015-08-04T18:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the time difference between fields, how do I properly convert the resulting value to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154383#M43425</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | eval comein=strptime(in,"%Y-%m-%d %H:%M:%S") | eval goout=strptime(out,"%Y-%m-%d %H:%M:%S") | eval diff= tostring(goout - comein,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2015 18:39:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154383#M43425</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-04T18:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the time difference between fields, how do I properly convert the resulting value to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154384#M43426</link>
      <description>&lt;P&gt;Thanks Pablo. When I add the %H,  returned in this case 19H, when the difference is less than 1 h, why?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2015 19:04:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154384#M43426</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2015-08-04T19:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the time difference between fields, how do I properly convert the resulting value to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154385#M43427</link>
      <description>&lt;P&gt;Works great, thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2015 20:23:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154385#M43427</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2015-08-04T20:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the time difference between fields, how do I properly convert the resulting value to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154386#M43428</link>
      <description>&lt;P&gt;ah sorry for the delayed response. not sure actually, but I'm glad you got a working answer from @somesoni2 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2015 00:11:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-the-time-difference-between-fields-how-do-I-properly/m-p/154386#M43428</guid>
      <dc:creator>ppablo</dc:creator>
      <dc:date>2015-08-11T00:11:44Z</dc:date>
    </item>
  </channel>
</rss>

