<?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: time conversion in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198856#M187446</link>
    <description>&lt;P&gt;Can u say how to convert milliseconds to seconds without decimal point. &lt;BR /&gt;
I tried the following search query..&lt;BR /&gt;
eval transfertime=toNumber(t/1000).The result i got is&lt;BR /&gt;
    transfertime&lt;BR /&gt;
       0.7161&lt;BR /&gt;
But I want the result as whole number.Is there any function in splunk to do that.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2014 05:22:18 GMT</pubDate>
    <dc:creator>Jananee_iNautix</dc:creator>
    <dc:date>2014-01-13T05:22:18Z</dc:date>
    <item>
      <title>time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198851#M187441</link>
      <description>&lt;P&gt;I want to convert time in HH:MM:SS format to milliseconds and vice versa.Can this be possible in splunk.&lt;BR /&gt;
For example:in my log I have time as&lt;BR /&gt;
2013-12-09 17:58:01 :Total time to upload [1340] ms&lt;/P&gt;

&lt;P&gt;I want to convert this to milliseconds and add to 1340 ms and convert that to HH:MM:SS format.Can anyone help me on this.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2014 13:28:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198851#M187441</guid>
      <dc:creator>Jananee_iNautix</dc:creator>
      <dc:date>2014-01-09T13:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198852#M187442</link>
      <description>&lt;P&gt;First of all, Splunk parses one timestamp from every event unless you configure it not to, and stores it in a field called &lt;CODE&gt;_time&lt;/CODE&gt;.  The &lt;CODE&gt;_time&lt;/CODE&gt; field is stored as a unix &lt;CODE&gt;time_t&lt;/CODE&gt; - or in "epoch" format.  That is, the # of seconds since Jan 1 1970 00:00:00 GMT.  It is highly likely that your &lt;CODE&gt;2013-12-09 17:58:01&lt;/CODE&gt; was already converted.  But if not there is a solution to that.&lt;/P&gt;

&lt;P&gt;The key here is field extraction.  You will need to make sure that &lt;CODE&gt;2013-12-09 17:58:01&lt;/CODE&gt; and &lt;CODE&gt;1340&lt;/CODE&gt; are extracted into fields.  For the sake of this discussion, let's say they are extracted into fields called &lt;CODE&gt;start_time&lt;/CODE&gt; and &lt;CODE&gt;upload_time_ms&lt;/CODE&gt;.  So&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;start_time=2013-12-09 17:58:01
upload_time_ms=1340
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Once we have this, then we can use the 'eval' command to convert &lt;CODE&gt;start_time&lt;/CODE&gt; into a &lt;CODE&gt;time_t&lt;/CODE&gt; value, add the value of &lt;CODE&gt;upload_time_ms&lt;/CODE&gt; to it, and then re-convert the resulting value into a formatted timestamp again.  It will go something like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval upload_end_time=strftime( 
     (strptime(start_time,"%Y-%m-%d %H:%M:%S") + upload_time_ms/1000), "%H:%M:%S" )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I got my parentheses and such matched up properly, this should do it.  I had to adjust the scale on upload_time_ms to make it seconds instead of milliseonds.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:36:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198852#M187442</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2020-09-28T15:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198853#M187443</link>
      <description>&lt;P&gt;Try this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your base search&amp;gt;| rex "\[(?&amp;lt;MS&amp;gt;.*)\]" | eval mytime=_time+(MS/1000) | eval NewTime=strftime(mytime,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jan 2014 14:35:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198853#M187443</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-01-09T14:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198854#M187444</link>
      <description>&lt;P&gt;Has the time to upload value been extracted as a field value yet?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2014 14:54:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198854#M187444</guid>
      <dc:creator>lukejadamec</dc:creator>
      <dc:date>2014-01-09T14:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198855#M187445</link>
      <description>&lt;P&gt;First you need to extract the time to upload as a field.  Try this to verify that it extracts the value correctly:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search |rex ".*upload\s\[(?P&amp;lt;uploadTime&amp;gt;\d+)\]"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Look for a new field called 'uploadTime' and verify that it has the correct value.&lt;/P&gt;

&lt;P&gt;Once that works, then this should do the math to convert _time to milliseconds, add the uploadTime, and convert the total time to a new field called totalTime.&lt;/P&gt;

&lt;P&gt;Here is an example using a Windows EventCode as the uploadTime:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main EventCode=* | rex ".*upload\s\[(?P&amp;lt;uploadTime&amp;gt;\d+)\]" | convert mktime(_time) as etime |eval mstime=(etime*1000)  |eval msttime=(mstime+EventCode)  |eval mstdtime=(msttime/1000) |convert timeformat="%H:%M:%S" ctime(mstdtime) AS totalTime | table  _time etime mstime msttime mstdtime totalTime EventCode
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is an example where the date and time are preserved:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main EventCode=* | rex ".*upload\s\[(?P&amp;lt;uploadTime&amp;gt;\d+)\]" | convert mktime(_time) as etime |eval mstime=(etime*1000)  |eval msttime=(mstime+EventCode)  |eval mstdtime=(msttime/1000) |convert  ctime(mstdtime) AS totalTime | table  _time etime mstime msttime mstdtime totalTime EventCode
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Once you get the extraction right, subsitute the EventCode field in the search and math with the uploadTime field.&lt;/P&gt;

&lt;P&gt;The totalTime should include decimal seconds.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2014 15:28:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198855#M187445</guid>
      <dc:creator>lukejadamec</dc:creator>
      <dc:date>2014-01-09T15:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198856#M187446</link>
      <description>&lt;P&gt;Can u say how to convert milliseconds to seconds without decimal point. &lt;BR /&gt;
I tried the following search query..&lt;BR /&gt;
eval transfertime=toNumber(t/1000).The result i got is&lt;BR /&gt;
    transfertime&lt;BR /&gt;
       0.7161&lt;BR /&gt;
But I want the result as whole number.Is there any function in splunk to do that.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2014 05:22:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198856#M187446</guid>
      <dc:creator>Jananee_iNautix</dc:creator>
      <dc:date>2014-01-13T05:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198857#M187447</link>
      <description>&lt;P&gt;if you want the ceiling value then use eval ceil() function or the floor function. You can use an if statement you decide which whole number will be appropriate. or you can also do  transfertime=toNumber(t%1000)...&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2014 06:48:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198857#M187447</guid>
      <dc:creator>linu1988</dc:creator>
      <dc:date>2014-01-13T06:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198858#M187448</link>
      <description>&lt;P&gt;or the &lt;CODE&gt;round()&lt;/CODE&gt; function may be even more appropriate;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval mytime = round(_time + MS / 1000, 0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2014 06:55:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198858#M187448</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-01-13T06:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: time conversion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198859#M187449</link>
      <description>&lt;P&gt;Thanks.it works&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2014 10:44:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/time-conversion/m-p/198859#M187449</guid>
      <dc:creator>Jananee_iNautix</dc:creator>
      <dc:date>2014-01-13T10:44:10Z</dc:date>
    </item>
  </channel>
</rss>

