<?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 How to convert time stamp? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330211#M98282</link>
    <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;How to convert the seconds in to days, hours, sec? Any suggestions ?&lt;/P&gt;

&lt;P&gt;for eg:&lt;/P&gt;

&lt;P&gt;I have a sec field to convert to "2 Day(s) 3 Hr. 12 Min. 5Sec." &lt;/P&gt;</description>
    <pubDate>Tue, 31 Oct 2017 01:34:58 GMT</pubDate>
    <dc:creator>kiran331</dc:creator>
    <dc:date>2017-10-31T01:34:58Z</dc:date>
    <item>
      <title>How to convert time stamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330211#M98282</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;How to convert the seconds in to days, hours, sec? Any suggestions ?&lt;/P&gt;

&lt;P&gt;for eg:&lt;/P&gt;

&lt;P&gt;I have a sec field to convert to "2 Day(s) 3 Hr. 12 Min. 5Sec." &lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 01:34:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330211#M98282</guid>
      <dc:creator>kiran331</dc:creator>
      <dc:date>2017-10-31T01:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert time stamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330212#M98283</link>
      <description>&lt;P&gt;Use REX to split the field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|rex field=text "(?&amp;lt;day&amp;gt;\d*)\sDay\(s\)\s(?&amp;lt;hr&amp;gt;\d*)\sHr\.\s(?&amp;lt;min&amp;gt;\d*)\sMin\.\s(?&amp;lt;sec&amp;gt;\d*)Sec.*"
|eval seconds=day*24*60*60+hr*60*60+min*60+sec
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Oct 2017 02:06:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330212#M98283</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2017-10-31T02:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert time stamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330213#M98284</link>
      <description>&lt;P&gt;@kiran331, Something similar has been answered before.&lt;BR /&gt;
1) Using &lt;CODE&gt;reltime&lt;/CODE&gt; command you can get relative difference of _time as per current time. However, it will be precise only to the highest unit of time i.e. &lt;CODE&gt;2 days 3 hours 30 min 20 sec&lt;/CODE&gt; will become &lt;CODE&gt;2 days ago&lt;/CODE&gt;. First you need to adjust _time as &lt;CODE&gt;now()-duration&lt;/CODE&gt; and then pipe &lt;CODE&gt;reltime&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;2) Using &lt;CODE&gt;tostring(duration,"duration")&lt;/CODE&gt; and then followed by &lt;CODE&gt;rex&lt;/CODE&gt; with &lt;CODE&gt;sed&lt;/CODE&gt; or &lt;CODE&gt;replace()&lt;/CODE&gt; function:&lt;/P&gt;

&lt;P&gt;Following is a run anywhere search with both examples:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval duration=3645
|  append 
    [|  makeresults
|  eval duration=84450]
|  append 
    [|  makeresults
|  eval duration=163431]
|  eval _time=now()-duration
|  reltime 
|  rename reltime as durRelTime
|  eval durDaysHHMMSS=tostring(duration,"duration")
|  eval durDaysHHMMSS=replace(durDaysHHMMSS,"\+"," Day(s) ")
|  eval durDaysHHMMSS=replace(durDaysHHMMSS,"(\d+):(\d+):(\d+)","\1 Hr. \2 Min. \3 Sec.")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Oct 2017 02:17:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330213#M98284</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-31T02:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert time stamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330214#M98285</link>
      <description>&lt;P&gt;Hi @kiran331&lt;/P&gt;

&lt;P&gt;You can use the splunk tostring and diff functions to convert a number in seconds to a range of days, hours, minutes, and seconds.&lt;BR /&gt;
tostring with the duration format will output the time as &lt;CODE&gt;[days]+[hours]:[minutes]:[seconds]&lt;/CODE&gt; ie: 2+03:12:05.  You can then use replace function of eval to format the output. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your search]
| eval duration = tostring([your time in seconds], "duration") 
| eval TimeRange=replace(duration,"(\d*)\+*(\d+):(\d+):(\d+)","\1 Day(s) \2 HR .\3 Min. \4 Sec.")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;More information on tostring can be found&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/ConversionFunctions#tostring.28X.2CY.29"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/ConversionFunctions#tostring.28X.2CY.29&lt;/A&gt;&lt;BR /&gt;
More information on Replace can be found &lt;BR /&gt;
 &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2017 21:16:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330214#M98285</guid>
      <dc:creator>LCM_BRogerson</dc:creator>
      <dc:date>2017-10-31T21:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert time stamp?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330215#M98286</link>
      <description>&lt;P&gt;Thank you! It worked&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 15:02:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-time-stamp/m-p/330215#M98286</guid>
      <dc:creator>kiran331</dc:creator>
      <dc:date>2017-11-01T15:02:24Z</dc:date>
    </item>
  </channel>
</rss>

