<?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: Trying to get reltime from last searched for event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57814#M14116</link>
    <description>&lt;P&gt;Thanks for the info on last. The documentation didn't jump out at me that it was the oldest. We're running 4.2.1 right now, so latest isn't an option right now. I'm trying to print out the relative time to a single value UI on my dashboard. When I use "searchstring | head 1 | reltime", I get the word "local" as output. How do I configure reltime to output the relative time instead of "local"? Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jan 2012 23:37:21 GMT</pubDate>
    <dc:creator>mmelnick</dc:creator>
    <dc:date>2012-01-27T23:37:21Z</dc:date>
    <item>
      <title>Trying to get reltime from last searched for event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57810#M14112</link>
      <description>&lt;P&gt;I'm trying to show the relative time for the last time data was refreshed successfully. I search for all success text strings in the log file and then I need to get that time and do a reltime. I tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchstring | stats last() as _time | reltime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But of course "stats last()" isn't a time and putting it into _time doesn't work. I tried extracting the fields from last(), concatenating them and then strptime'ing then assigning it to _time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchstring | stats last(date_hour) as HOUR, last(date_minute) as MINUTE, last(date_year) as YEAR, last(date_month) as MONTH, last(date_second) as SECOND, last(date_mday) as DAYN | eval _time=strptime(YEAR . "-" . MONTH . "-" . DAYN . " " . HOUR . ":" . MINUTE . " " . SECOND,"%Y-%B-%d %H:%M:%S") | reltime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it only added a reltime column to the result and put in unknown for the value, so I'm still doing something wrong. Besides, I &lt;STRONG&gt;really&lt;/STRONG&gt; hope there's an easier way to do this than that last query (yuck!)&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 18:24:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57810#M14112</guid>
      <dc:creator>mmelnick</dc:creator>
      <dc:date>2012-01-25T18:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get reltime from last searched for event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57811#M14113</link>
      <description>&lt;P&gt;I managed to get it to work by extending the ugly query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchstring | stats last(date_hour) as HOUR, last(date_minute) as MINUTE, last(date_year) as YEAR, last(date_month) as MONTH, last(date_second) as SECOND, last(date_mday) as DAYN | eval timestr=YEAR . "-" . MONTH . "-" . DAYN . " " . HOUR . ":" . MINUTE . ":" . SECOND  | eval _time=strptime(timestr,"%Y-%B-%d %H:%M:%S") | reltime | fields reltime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Still hoping someone has a nicer solution for this.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2012 21:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57811#M14113</guid>
      <dc:creator>mmelnick</dc:creator>
      <dc:date>2012-01-25T21:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get reltime from last searched for event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57812#M14114</link>
      <description>&lt;P&gt;First of all, what are you planning to do with that value? Print it by itself? Pass it to something? Create a table of them? There may be better ways to do whatever you want, using a different path.&lt;/P&gt;

&lt;P&gt;To answer the narrow problem you have, it's much simpler than what you've been doing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchstring | head 1 | reltime 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;At least, that's what you do if you want the most recent time. your above query is getting you &lt;CODE&gt;last()&lt;/CODE&gt;, which is actually the oldest time in your search. (Because Splunk returns results in reverse-time order, &lt;CODE&gt;first()&lt;/CODE&gt; is the most recent event, and &lt;CODE&gt;last()&lt;/CODE&gt; is the oldest. Starting in 4.3, you can use &lt;CODE&gt;latest()&lt;/CODE&gt; and &lt;CODE&gt;earliest()&lt;/CODE&gt; instead so it's less confusing.) If you really wanted the oldest event, then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchstring | tail 1 | reltime 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your first try would have worked a lot easier if you just did:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchstring | stats latest(_time) as _time | reltime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But using &lt;CODE&gt;head&lt;/CODE&gt; (if you really mean the most recent time) is more efficient, or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchstring | stats last(_time) as _time | reltime 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if you really meant &lt;CODE&gt;last()&lt;/CODE&gt;, i.e., the oldest.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2012 05:35:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57812#M14114</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2012-01-26T05:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get reltime from last searched for event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57813#M14115</link>
      <description>&lt;P&gt;also note that your method will give wrong results if the time zone of your data is different from the time zone of the search head. (assuming the time zone is correctly identified.)&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2012 05:36:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57813#M14115</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2012-01-26T05:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get reltime from last searched for event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57814#M14116</link>
      <description>&lt;P&gt;Thanks for the info on last. The documentation didn't jump out at me that it was the oldest. We're running 4.2.1 right now, so latest isn't an option right now. I'm trying to print out the relative time to a single value UI on my dashboard. When I use "searchstring | head 1 | reltime", I get the word "local" as output. How do I configure reltime to output the relative time instead of "local"? Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2012 23:37:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57814#M14116</guid>
      <dc:creator>mmelnick</dc:creator>
      <dc:date>2012-01-27T23:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get reltime from last searched for event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57815#M14117</link>
      <description>&lt;P&gt;Hmm, not sure. I hven't really used &lt;CODE&gt;reltime&lt;/CODE&gt;. If you instead use &lt;CODE&gt;eval tm=strftime(_time,"%Y-%m-%d %H:%M:%S")&lt;/CODE&gt; and show &lt;CODE&gt;tm&lt;/CODE&gt;, does it display the right time? Also, are you sure you're not accidentally setting &lt;CODE&gt;_time&lt;/CODE&gt; or overriding it, or accidentally printing out &lt;CODE&gt;date_zone&lt;/CODE&gt; instead of the &lt;CODE&gt;reltime&lt;/CODE&gt; field?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Jan 2012 04:48:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57815#M14117</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2012-01-28T04:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get reltime from last searched for event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57816#M14118</link>
      <description>&lt;P&gt;Well, I'm not sure what's going on now. Putting your eval suggestion at the end gives me the time of the event which is what I'd expect. I put in exactly what you had, so no overriding _time. To further muddy the waters, it works for one search string, but not another. Both strings occur once each in the indexed data, so it should find both of them normally and do the reltime step. But instead, one works and the other doesn't. The eval step works for both as well, so I dunno. Bewildering to say the least! Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2012 20:17:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Trying-to-get-reltime-from-last-searched-for-event/m-p/57816#M14118</guid>
      <dc:creator>mmelnick</dc:creator>
      <dc:date>2012-01-30T20:17:34Z</dc:date>
    </item>
  </channel>
</rss>

