<?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: How can I do sum of a time field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346472#M159566</link>
    <description>&lt;P&gt;I were able to figure out how to get the answer here:&lt;/P&gt;

&lt;P&gt;....| convert num("Call Duration") | stats sum("Call Duration") as "TotalCD" | eval "TotalCD"=tostring($TotalCD$,"duration")&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2017 19:14:41 GMT</pubDate>
    <dc:creator>tamduong16</dc:creator>
    <dc:date>2017-08-03T19:14:41Z</dc:date>
    <item>
      <title>How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346468#M159562</link>
      <description>&lt;P&gt;Hi I'm new to Splunk and currently trying to understand how the search function work. How could I get Splunk to display the sum of call duration in total from all of my events? Thanks!&lt;/P&gt;

&lt;P&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/3303iE5E4320EFD631DAD/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>Wed, 02 Aug 2017 20:43:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346468#M159562</guid>
      <dc:creator>tamduong16</dc:creator>
      <dc:date>2017-08-02T20:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346469#M159563</link>
      <description>&lt;P&gt;Lots of ways, depending on what you want.  &lt;/P&gt;

&lt;P&gt;If you just want to know the sum of all those, and don't need the details, then... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats sum("Call Duration") as "Call Duration"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to keep the details and just add a totals line at the bottom for only the Call Duration field...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| addtotals row=f col=t "Call Duration"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to append an additional totals line after all the prior lines with the total call duration, the maximum max latency, and the average call rate&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| appendpipe [| stats sum("Call Duration") as "Call Duration" max("Max Latency Rx") as "Max Latency Rx" avg("Call Rate") as "Call Rate"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;All of those depend on the assumption that the duration is a value in seconds, that has just been told to format itself as you have shown.  If it is actually a character value, then you are going to have to strptime it first in order to be able to do the calculations. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Call Duration"= strptime("Call Duration","%H:%M:%S")
... one of the above things ...
| eval "Call Duration"= if("Call Duration"&amp;gt;86400,floor("Call Duration"/86400)." Days ".round(("Call Duration"/86400)/3600,2)." Hours" ,strftime("Call Duration","%H:%M:%S"))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 22:39:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346469#M159563</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-02T22:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346470#M159564</link>
      <description>&lt;P&gt;For some reason, the first stats command didn't show up anything.&lt;BR /&gt;
The eval "Call Duration"= strptime("Call Duration","%H:%M:%S") give me nothing under Call Duration. It doesn't have a zero or anything display.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 14:07:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346470#M159564</guid>
      <dc:creator>tamduong16</dc:creator>
      <dc:date>2017-08-03T14:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346471#M159565</link>
      <description>&lt;P&gt;your base search | eval tp = "Call Duration" | rename  "Max Latency Rx" as lrx, "Call Rate" as cr |  convert dur2sec(tp) as tp | stats sum(tp) as tp by lrx cr | eval tp= if(tp&amp;gt;86400,floor(tp/86400)." Days ".round((tp/86400)/3600,2)." Hours" ,strftime(tp,"%H:%M:%S")) | rename lrx as "Max Latency Rx", cr as "Call Rate" | table "Call Duration", "Max Latency Rx",  "Call Rate" , tp&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 16:12:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346471#M159565</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-08-03T16:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346472#M159566</link>
      <description>&lt;P&gt;I were able to figure out how to get the answer here:&lt;/P&gt;

&lt;P&gt;....| convert num("Call Duration") | stats sum("Call Duration") as "TotalCD" | eval "TotalCD"=tostring($TotalCD$,"duration")&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 19:14:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346472#M159566</guid>
      <dc:creator>tamduong16</dc:creator>
      <dc:date>2017-08-03T19:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346473#M159567</link>
      <description>&lt;P&gt;hmmm.  You have a single-digit hour there.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval "Call Duration"= if(len("Call Duration")=7,"0","")."Call Duration" 
| eval "Call Duration"= strptime("Call Duration","%H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 19:57:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346473#M159567</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-03T19:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346474#M159568</link>
      <description>&lt;P&gt;Yeah, those renames help the code be less ugly a lot, don't they?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 19:59:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346474#M159568</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-03T19:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346475#M159569</link>
      <description>&lt;P&gt;You'd better verify against a couple of events that you are getting the correct result.  If the "Call Duration" field was already in duration, then that would work.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 20:41:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/346475#M159569</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-03T20:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/665712#M228392</link>
      <description>&lt;P&gt;This worked fine for me to get to seconds, then I just did /60/60 to get to hours which is what I wanted to sum up.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 18:05:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/665712#M228392</guid>
      <dc:creator>sjbriggs</dc:creator>
      <dc:date>2023-10-20T18:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do sum of a time field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/665723#M228399</link>
      <description>&lt;P&gt;This&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;eval durations = tostring(durAsSec, "duration")&lt;/LI-CODE&gt;&lt;P&gt;gives to you also days, hours and minutes. Just select those from that string.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 21:31:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-sum-of-a-time-field/m-p/665723#M228399</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2023-10-20T21:31:38Z</dc:date>
    </item>
  </channel>
</rss>

