<?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: Why the  function &amp;quot;strftime&amp;quot; not working in my search query? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193554#M55727</link>
    <description>&lt;P&gt;Please take a look&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/139i4CEFA123B256DE3C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Nov 2014 08:29:05 GMT</pubDate>
    <dc:creator>chrismok</dc:creator>
    <dc:date>2014-11-05T08:29:05Z</dc:date>
    <item>
      <title>Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193538#M55711</link>
      <description>&lt;P&gt;alt textIf I use this, no event return&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc source="*"+strftime(now(),"%Y%m%d")+"*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But when I modify the query to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc source="*20141104*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is a events return.&lt;/P&gt;

&lt;P&gt;May I know is that a bug in Splunk?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 04:37:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193538#M55711</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-04T04:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193539#M55712</link>
      <description>&lt;P&gt;Hi chrismok,&lt;/P&gt;

&lt;P&gt;Its not a bug in splunk,&lt;/P&gt;

&lt;P&gt;strftime is a function that takes epoch time as first parameter and format human readable format like YYYYDDMM etc, based on your format string in second param.&lt;/P&gt;

&lt;P&gt;you should use those functions in "&lt;STRONG&gt;eval&lt;/STRONG&gt;". &lt;/P&gt;

&lt;P&gt;As per your requirement this query will help you. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc [|gentimes start=-1 | eval source="*"+strftime(now(),"%Y%m%d")+"*" | return source]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Vasu&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 05:09:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193539#M55712</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2014-11-04T05:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193540#M55713</link>
      <description>&lt;P&gt;Thanks vasanthmss. But I found that the performance will be decreased using your approach&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc [|gentimes start=-1 | eval source="*"+strftime(now(),"%Y%m%d")+"*" | return source] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Run time: 3~4 seconds, Retrieve events: 18824&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc source="*20141104*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Run time: 1 seconds, Retrieve events: 18824&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 07:13:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193540#M55713</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-04T07:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193541#M55714</link>
      <description>&lt;P&gt;Hi chrismok,&lt;/P&gt;

&lt;P&gt;you're absolutly right regarding the performance. Try this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval file_date=strftime(now(), "%Y%m%d") | eval mySource="*" + file_date + "*" |  where source=mySource | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 07:23:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193541#M55714</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-04T07:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193542#M55715</link>
      <description>&lt;P&gt;What if you try adding the specific field name to the search - something like &lt;BR /&gt;
     sourcetype=abc source=[|gentimes start=-1 | eval source="&lt;EM&gt;"+strftime(now(),"%Y%m%d")+"&lt;/EM&gt;" | return source]&lt;/P&gt;

&lt;P&gt;Does that improve the performance?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 07:24:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193542#M55715</guid>
      <dc:creator>davebrooking</dc:creator>
      <dc:date>2014-11-04T07:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193543#M55716</link>
      <description>&lt;P&gt;Error in 'search' command: Unable to parse the search: Comparator '=' has an invalid term on the left hand side. &lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 07:52:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193543#M55716</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-04T07:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193544#M55717</link>
      <description>&lt;P&gt;Hi MuS.&lt;/P&gt;

&lt;P&gt;Using your script, no record found.....&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Chris&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 07:53:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193544#M55717</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-04T07:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193545#M55718</link>
      <description>&lt;P&gt;upps my bad...try this updated command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval file_date=strftime(now(), "%Y%m%d") | eval mySource="." + file_date + "." | where match(source, mySource) | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Nov 2014 08:28:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193545#M55718</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-04T08:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193546#M55719</link>
      <description>&lt;P&gt;worser&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/138i95A8E53F504FB34C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 08:48:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193546#M55719</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-04T08:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193547#M55720</link>
      <description>&lt;P&gt;Sorry, I was using the concept from &lt;A href="http://answers.splunk.com/answers/177322/can-you-use-if-statements-in-the-search-query-itse.html"&gt;this answer&lt;/A&gt;, but had no Splunk instance to test on.&lt;/P&gt;

&lt;P&gt;I've since had a chance to try the technique on a small subset of data and noticed quite sizeable differences in execution time depending on whether you use stats count or gentimes start=-1 at the start of the subsearch with return or table as the last command in the subsearch. I'm getting consistently better execution times using &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc [|stats count | eval source="*"+strftime(now(),"%Y%m%d")+"*" | table source]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Nov 2014 09:34:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193547#M55720</guid>
      <dc:creator>davebrooking</dc:creator>
      <dc:date>2014-11-04T09:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193548#M55721</link>
      <description>&lt;P&gt;Here is what you are looking for&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=abc [|stats count | eval source = "*"+strftime(now(),"%Y%m%d")+"*" | fields source | format]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Edited Answer to show the better performance solution found by davebrooking, but optimized a little by me. &lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 09:34:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193548#M55721</guid>
      <dc:creator>peter_krammer</dc:creator>
      <dc:date>2014-11-04T09:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193549#M55722</link>
      <description>&lt;P&gt;looking at this picture, it's absolutely clear why your first search is the fastest: using any fields like index or source in the base search will speed up the search. Using a sub search will basically double search times but also speeds up the base search because you can use source in it and mine example simply does not provide any source field in the base search. &lt;/P&gt;</description>
      <pubDate>Tue, 04 Nov 2014 09:57:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193549#M55722</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-04T09:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193550#M55723</link>
      <description>&lt;P&gt;another approach just came up my mind:&lt;BR /&gt;
if you always need today's or yesterday's date in the source name, than you could use an eval based macro containing something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;strftime(relative_time(time(), "-d"), "%Y%m%d") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If your macro is named &lt;CODE&gt;yesterday&lt;/CODE&gt; you can use it like this in your searches:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=depmon_sys_rel_log  source=*`yesterday`* | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Nov 2014 10:26:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193550#M55723</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-04T10:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193551#M55724</link>
      <description>&lt;P&gt;It's not worked...  as the Splunk macro is not similar to excel macro or function.... The Splunk only copy the macro string and place to the query&lt;/P&gt;

&lt;P&gt;for example.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=depmon_sys_rel_log source=`get_today`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Macro: get_today&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;strftime(now(),"%Y%m%d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After ran the query and click the Search job inspecor. You can see that&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search sourcetype=depmon_sys_rel_log source=strftime(now(),"%Y%m%d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As a result, it is not worked&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 01:38:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193551#M55724</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-05T01:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193552#M55725</link>
      <description>&lt;P&gt;Tested for your solution, it can provide the better performance&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 01:53:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193552#M55725</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-05T01:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193553#M55726</link>
      <description>&lt;P&gt;Well there must be something wrong, because this works for sure. If I run a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main source=*`yesterday`* 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;it becomes this litsearch&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=main source=*04-Nov-2014*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and returns events ....&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 07:17:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193553#M55726</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-05T07:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193554#M55727</link>
      <description>&lt;P&gt;Please take a look&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/139i4CEFA123B256DE3C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 08:29:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193554#M55727</guid>
      <dc:creator>chrismok</dc:creator>
      <dc:date>2014-11-05T08:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193555#M55728</link>
      <description>&lt;P&gt;Make sure you tick the &lt;CODE&gt;Use eval-based definition?&lt;/CODE&gt; in the macro settings! Then it will work and should be pretty fast as well &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;hmm, cannot add a screenshot here???&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 09:15:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193555#M55728</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-05T09:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193556#M55729</link>
      <description>&lt;P&gt;I just tried out your solution and it &lt;STRONG&gt;works&lt;/STRONG&gt;, if eval-based definition is checked. &lt;BR /&gt;
So thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 12:38:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193556#M55729</guid>
      <dc:creator>peter_krammer</dc:creator>
      <dc:date>2014-11-05T12:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why the  function "strftime" not working in my search query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193557#M55730</link>
      <description>&lt;P&gt;you're welcome &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 13:07:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-the-function-quot-strftime-quot-not-working-in-my-search/m-p/193557#M55730</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-05T13:07:59Z</dc:date>
    </item>
  </channel>
</rss>

