<?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 do you turn a string into time format for editable stats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391821#M114049</link>
    <description>&lt;P&gt;I need to see the &lt;CODE&gt;StartTime&lt;/CODE&gt; and &lt;CODE&gt;EndTime&lt;/CODE&gt; format. This is most likely the cause of the incorrect SumDuration. &lt;/P&gt;</description>
    <pubDate>Thu, 03 Jan 2019 22:03:38 GMT</pubDate>
    <dc:creator>skoelpin</dc:creator>
    <dc:date>2019-01-03T22:03:38Z</dc:date>
    <item>
      <title>How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391818#M114046</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have been trying to use the stats command to determine the duration of a certain event. When I add the data, the start and end times upload as a string, but I need to convert it to time format in order to eval and output a total duration of the event. The output with the following code gives me 22:49:41, which should not be the final answer. What am I doing wrong?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Start= strptime(StartTime,"%m/%d/%y %H:%M:%S %p"), End= strptime(EndTime,"%m/%d/%y %H:%M:%S %p")
| eval Duration=End-Start| stats sum(Duration) as SumDuration
| fieldformat SumDuration=strftime(SumDuration,"%H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Jan 2019 20:51:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391818#M114046</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2019-01-03T20:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391819#M114047</link>
      <description>&lt;P&gt;Splunk uses epoch time by default so the math will be much easier and more accurate compared to doing it with a non standard human readable timestamp. I'm guessing that &lt;CODE&gt;StartTime&lt;/CODE&gt; and &lt;CODE&gt;EndTime&lt;/CODE&gt; are not in epoch time format. You should check this &lt;/P&gt;

&lt;P&gt;It's also possible that your strftime is incorrect. Can you post the value?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 21:38:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391819#M114047</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2019-01-03T21:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391820#M114048</link>
      <description>&lt;P&gt;Hello skoelpin,&lt;/P&gt;

&lt;P&gt;The SumDuration answer is 22:49:41, but it should be a sum of about 5 hours. StartTime and EndTime upload in a string format, so I can not use the stats command, SPLUNK gives me an error.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 21:57:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391820#M114048</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2019-01-03T21:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391821#M114049</link>
      <description>&lt;P&gt;I need to see the &lt;CODE&gt;StartTime&lt;/CODE&gt; and &lt;CODE&gt;EndTime&lt;/CODE&gt; format. This is most likely the cause of the incorrect SumDuration. &lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 22:03:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391821#M114049</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2019-01-03T22:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391822#M114050</link>
      <description>&lt;P&gt;The StartTime and EndTime format are a string and were uploaded as:&lt;/P&gt;

&lt;P&gt;12/22/18 10:04:29 AM&lt;/P&gt;

&lt;P&gt;When converted with strptime (| eval Start= strptime(StartTime,"%m/%d/%y %H:%M:%S %p") &lt;BR /&gt;
), one event looks like: &lt;BR /&gt;
1545483185.000000&lt;/P&gt;

&lt;P&gt;Sum Duration is then:&lt;/P&gt;

&lt;P&gt;100181.000000 &lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 14:33:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391822#M114050</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2019-01-04T14:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391823#M114051</link>
      <description>&lt;P&gt;I don't think you can use strf on arbitrary times - its expecting to convert from epoch&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 14:40:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391823#M114051</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-01-04T14:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391824#M114052</link>
      <description>&lt;P&gt;Instead of the final "strftime" try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;totalDuration=tostring(SumDuration, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Jan 2019 14:49:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391824#M114052</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-01-04T14:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391825#M114053</link>
      <description>&lt;P&gt;The way you are converting into Hour, minute and Second from epoch time is converting data correctly but it is actually converting to Date &lt;CODE&gt;02/01/1970 04:49:41&lt;/CODE&gt; for me because my user is in GMT (As it depends on user timezone), If I change user timezone to &lt;CODE&gt;GMT-5&lt;/CODE&gt; then it will give me &lt;CODE&gt;22:49:41&lt;/CODE&gt; which is actually &lt;CODE&gt;01/01/1970 22:49:41&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If you want to convert time difference or duration into string then use &lt;CODE&gt;eval SumDuration=tostring(SumDuration, "duration")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 14:51:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391825#M114053</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-01-04T14:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391826#M114054</link>
      <description>&lt;P&gt;as commented by @harsmarvania57 below - i think the above works - here is a run anywhere example which works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval StartTime="12/22/18 10:04:29 AM" 
| eval EndTime="12/23/18 15:04:29 AM" 
| eval Start= strptime(StartTime,"%m/%d/%y %H:%M:%S %p"), End= strptime(EndTime,"%m/%d/%y %H:%M:%S %p") 
| eval Duration=End-Start 
| stats sum(Duration) as SumDuration 
| eval totalDuration=tostring(SumDuration, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It should give you 1 day + 5 hours&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 14:54:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391826#M114054</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-01-04T14:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391827#M114055</link>
      <description>&lt;P&gt;I want to show the final duration in hh:mm:ss, not as a string value.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:16:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391827#M114055</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2019-01-04T15:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391828#M114056</link>
      <description>&lt;P&gt;I want to show the final duration in hh:mm:ss, not as a string value. Also, I don't think the answer is 22:49:41, it is a very big value. This is the same answer I am getting. &lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:17:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391828#M114056</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2019-01-04T15:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391829#M114057</link>
      <description>&lt;P&gt;The above will do that (if its less than 1 day).&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:21:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391829#M114057</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-01-04T15:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391830#M114058</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults 
 | eval StartTime="12/22/18 10:04:29 AM" 
 | eval EndTime="12/23/18 10:14:19 AM" 
 | eval Start= strptime(StartTime,"%m/%d/%y %I:%M:%S %p"), End= strptime(EndTime,"%m/%d/%y %I:%M:%S %p") 
 | eval Duration=End-Start 
 | stats sum(Duration) as duration
 | eval f_hr=floor(duration/3600), f_min=floor(duration/(60)) % 60, f_sec=floor(duration % 60)
 | eval f_hr=if(len(f_hr)=1, "0".tostring(f_hr),tostring(f_hr)), f_min=if(len(f_min)=1, "0".tostring(f_min),tostring(f_min)), f_sec=if(len(f_sec)=1, "0".tostring(f_sec),tostring(f_sec))
 | eval SumDuration=f_hr.":".f_min.":".f_sec
 | fields - f_hr,f_min,f_sec
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;EDIT: Updated above query (Found that you are using &lt;CODE&gt;%H&lt;/CODE&gt; with &lt;CODE&gt;%p&lt;/CODE&gt; which will not work because &lt;CODE&gt;%H&lt;/CODE&gt; is 24 hour format so there will be no meaning of &lt;CODE&gt;%p&lt;/CODE&gt; if you change it to AM or PM it will give you same result so I have updated &lt;CODE&gt;%H&lt;/CODE&gt; to &lt;CODE&gt;%I&lt;/CODE&gt; in above query)&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 15:35:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391830#M114058</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-01-04T15:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391831#M114059</link>
      <description>&lt;P&gt;Oh ok!! Perfect, now I just have to figure out how to subtract one day in epoch time. &lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:04:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391831#M114059</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2019-01-04T16:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391832#M114060</link>
      <description>&lt;P&gt;Thank you! This was perfect! &lt;/P&gt;</description>
      <pubDate>Fri, 04 Jan 2019 16:05:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391832#M114060</guid>
      <dc:creator>tonahoyos</dc:creator>
      <dc:date>2019-01-04T16:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do you turn a string into time format for editable stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391833#M114061</link>
      <description>&lt;P&gt;Splunk uses epoch time for its base time. You should do the math on epoch time rather than the string formatted time. Your sum duration is number of seconds, so if you divide by 3600, you get ~27.8 hours&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 15:00:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-turn-a-string-into-time-format-for-editable-stats/m-p/391833#M114061</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2019-01-07T15:00:41Z</dc:date>
    </item>
  </channel>
</rss>

