<?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 convert duration to seconds? &amp;quot;1h 2m 3s&amp;quot; to 3723 in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432376#M123543</link>
    <description>&lt;P&gt;I was able to come up with a solution for this as well... my solution is probably less performant.... not sure.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=timeraw, "(?&amp;lt;minutes&amp;gt;\d{1,2})m" | rex field=timeraw, "(?&amp;lt;seconds&amp;gt;\d{1,2})s" | fillnull | eval totalseconds=seconds+(minutes*60) | timechart span=1d avg(totalseconds) as AverageUploadTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 May 2018 16:45:26 GMT</pubDate>
    <dc:creator>arianf</dc:creator>
    <dc:date>2018-05-31T16:45:26Z</dc:date>
    <item>
      <title>How can I convert duration to seconds? "1h 2m 3s" to 3723</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432374#M123541</link>
      <description>&lt;P&gt;I have a a field that is called rawtime that has a bunch of durations. My end goal is to graph per hour the average duration.&lt;/P&gt;

&lt;P&gt;I'm stuck at being able to convert the duration as it's being logged into seconds.&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/5105i99BF0673C2E447F1/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>Thu, 31 May 2018 02:39:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432374#M123541</guid>
      <dc:creator>arianf</dc:creator>
      <dc:date>2018-05-31T02:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I convert duration to seconds? "1h 2m 3s" to 3723</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432375#M123542</link>
      <description>&lt;P&gt;@arianf, you can use &lt;CODE&gt;convert&lt;/CODE&gt; command with &lt;CODE&gt;dur2sec()&lt;/CODE&gt; function, however, it expects the Duration time string in the following format: (1) With days included included &lt;CODE&gt;d+HH:MM:SS&lt;/CODE&gt; (2) Without Days: &lt;CODE&gt;HH:MM:SS&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;So you would need to create a separate eval to format your Time Duration to above format first (the eval can be saved as &lt;CODE&gt;Calculated Field&lt;/CODE&gt; and/or &lt;CODE&gt;Macro&lt;/CODE&gt; for maintenance and scalability. If time duration is absolute the following expects lower time units will be also present (if not the conditions will change and more conditions will be required) i.e. If exact &lt;CODE&gt;1 hour&lt;/CODE&gt; duration is present it be be &lt;CODE&gt;1h 0m 1s&lt;/CODE&gt; in log.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval timeraw="2d 1h 20m 30s,1h 31m 23s,30s,1m 24s" 
| makemv timeraw delim="," 
| mvexpand timeraw 
| eval timeInSec=case(match(timeraw,"^\d+d\s\d+h\s\d+m\s\d+s$"),replace(replace(replace(timeraw,"d\s","+"),"h|m|s","")," ",":"),
                      match(timeraw,"^\d+h\s\d+m\s\d+s$"),replace(replace(timeraw,"h|m|s","")," ",":"),
                      match(timeraw,"^\d+m\s\d+s$"),"00:".replace(replace(timeraw,"m|s","")," ",":"),
                      match(timeraw,"^\d+s$"),"00:00:".replace(replace(timeraw,"m|s","")," ",":")) 
| eval timeFormatted=timeInSec 
| convert dur2sec(timeInSec)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm!&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 06:25:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432375#M123542</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-31T06:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can I convert duration to seconds? "1h 2m 3s" to 3723</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432376#M123543</link>
      <description>&lt;P&gt;I was able to come up with a solution for this as well... my solution is probably less performant.... not sure.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=timeraw, "(?&amp;lt;minutes&amp;gt;\d{1,2})m" | rex field=timeraw, "(?&amp;lt;seconds&amp;gt;\d{1,2})s" | fillnull | eval totalseconds=seconds+(minutes*60) | timechart span=1d avg(totalseconds) as AverageUploadTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 16:45:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432376#M123543</guid>
      <dc:creator>arianf</dc:creator>
      <dc:date>2018-05-31T16:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I convert duration to seconds? "1h 2m 3s" to 3723</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432377#M123544</link>
      <description>&lt;P&gt;I was thinking along those lines as well. The solution from @niketnilay is nice in the sense that it allows you to use the convert command, but the pre-processing looks quite complex to me. Having to perform multiple matches and then a double replace. Wouldn't be surprised if simply extracting minutes and seconds and calculating the seconds like you do turns out more efficient. At least it is a hell of a lot easier to read and that's worth a lot if you ask me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 16:58:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432377#M123544</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-05-31T16:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I convert duration to seconds? "1h 2m 3s" to 3723</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432378#M123545</link>
      <description>&lt;P&gt;@arianf glad you were able to figure out your solution... ain't that the greatest feeling &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;@FrankVI, yeah first I thought it was easy, then I realized... ooops I have traversed the wrong path &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 17:12:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-convert-duration-to-seconds-quot-1h-2m-3s-quot-to-3723/m-p/432378#M123545</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-31T17:12:21Z</dc:date>
    </item>
  </channel>
</rss>

