<?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: Return date string from a subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386457#M112787</link>
    <description>&lt;P&gt;Works like a charm! Thank you. Any idea why this method works and my original one did not?&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2019 19:52:10 GMT</pubDate>
    <dc:creator>maxzintel</dc:creator>
    <dc:date>2019-04-01T19:52:10Z</dc:date>
    <item>
      <title>Return date string from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386455#M112785</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I am attempting to rename a column titled 'Yesterday' with yesterday's date. The goal is it would look like this: 'Yesterday (2019-03-31 UTC)'.&lt;/P&gt;

&lt;P&gt;My initial solution to this was using a subsearch to output a strftime date that was converting the relative_time Unix timestamp of the end of yesterday. Code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename Yesterday as [search index=example (earliest=-1d@d latest=@d) 
| eval endOfYesterday=relative_time(now(), "-1d@d")
| eval endDate=strftime(endOfYesterday, "%Y-%m-%d")
| eval yesterdayFieldName="\"Yesterday (".endDate." UTC)\""
| return $yesterdayFieldName]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As of recently, this was working. Outside of a subsearch/rename, it still outputs the correct values. I haven't altered the search at all since then. The only things I can think of that changed between then and now that are possibly relevant is that we updated from Splunk Enterprise 7.2.1 to 7.2.4, and the US had daylight savings time.&lt;/P&gt;

&lt;P&gt;Other potentially relevant info: I can pass an integer through the return (like stats count as num and swapping endDate for num in yesterdayFieldName) and it works. The error message I get is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'rename' command: Usage: rename [old_name AS/TO/-&amp;gt; new_name]+.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If anyone has any insight into what may be happening here or workarounds I can try, it would be much appreciated! Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 16:07:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386455#M112785</guid>
      <dc:creator>maxzintel</dc:creator>
      <dc:date>2019-04-01T16:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Return date string from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386456#M112786</link>
      <description>&lt;P&gt;Use this instead&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename Yesterday as [ | makeresults 
 | eval search="\"Yesterday (".strftime( relative_time(now(),"-1d@d"),"%Y-%m-%d)\"")
 | table search]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Apr 2019 19:39:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386456#M112786</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-04-01T19:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Return date string from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386457#M112787</link>
      <description>&lt;P&gt;Works like a charm! Thank you. Any idea why this method works and my original one did not?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 19:52:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386457#M112787</guid>
      <dc:creator>maxzintel</dc:creator>
      <dc:date>2019-04-01T19:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Return date string from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386458#M112788</link>
      <description>&lt;P&gt;I believe your base search in that subsearch (&lt;CODE&gt;index=example (earliest=-1d@d latest=@d)&lt;/CODE&gt;) might not be returning anything. Since you want to return a index-independent value, I would rather use &lt;CODE&gt;makeresults&lt;/CODE&gt; than doing a search on an index.&lt;/P&gt;

&lt;P&gt;You can confirm that by running this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rename Yesterday as [| makeresults 
 | eval endOfYesterday=relative_time(now(), "-1d@d")
 | eval endDate=strftime(endOfYesterday, "%Y-%m-%d")
 | eval yesterdayFieldName="\"Yesterday (".endDate." UTC)\""
 | return $yesterdayFieldName]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386458#M112788</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-04-01T20:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Return date string from a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386459#M112789</link>
      <description>&lt;P&gt;You are right. Since there were no events in the specified range &lt;CODE&gt;(earliest=-1d@d latest=@d)&lt;/CODE&gt; I believe I was unable to get any timestamps to run &lt;CODE&gt;relative_time()&lt;/CODE&gt; against. Thanks a bunch again! This was very helpful.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 20:51:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-date-string-from-a-subsearch/m-p/386459#M112789</guid>
      <dc:creator>maxzintel</dc:creator>
      <dc:date>2019-04-01T20:51:06Z</dc:date>
    </item>
  </channel>
</rss>

