<?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: How to use macros to set time variable in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149571#M1448</link>
    <description>&lt;P&gt;I think the main problem is that you are using &lt;CODE&gt;"-1d"&lt;/CODE&gt; instead of &lt;CODE&gt;"-1h"&lt;/CODE&gt;.  In any case, it should look like this in macros.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[TimeLessOneHour(2)]
args = OldTime, NewTime
definition = eval $NewTime$ = strftime(relative_time($OldTime$, "-1h"), "%Y%m%d%H")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And you should call it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... |`TimeLessOneHour(_time, time)` | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also beware that you must pass in an &lt;CODE&gt;epoch&lt;/CODE&gt; time for &lt;CODE&gt;OldTime&lt;/CODE&gt; or it will not work because &lt;CODE&gt;relative_time&lt;/CODE&gt; requires &lt;CODE&gt;epoch&lt;/CODE&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jul 2015 15:15:11 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-07-30T15:15:11Z</dc:date>
    <item>
      <title>How to use macros to set time variable</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149570#M1447</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to configure macros to use as a variable in my source. In my macro, I use &lt;CODE&gt;strftime(relative_time(time(), "-1d"), "%Y%m%d%H")&lt;/CODE&gt;, to get it to print the date string in &lt;CODE&gt;YYYYMMDDHH&lt;/CODE&gt;, which HH is the previous hour, but it doesn't seems to work.&lt;/P&gt;

&lt;P&gt;Is there anything I got wrong?&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2015 13:17:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149570#M1447</guid>
      <dc:creator>leonheart78</dc:creator>
      <dc:date>2015-07-30T13:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macros to set time variable</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149571#M1448</link>
      <description>&lt;P&gt;I think the main problem is that you are using &lt;CODE&gt;"-1d"&lt;/CODE&gt; instead of &lt;CODE&gt;"-1h"&lt;/CODE&gt;.  In any case, it should look like this in macros.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[TimeLessOneHour(2)]
args = OldTime, NewTime
definition = eval $NewTime$ = strftime(relative_time($OldTime$, "-1h"), "%Y%m%d%H")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And you should call it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... |`TimeLessOneHour(_time, time)` | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also beware that you must pass in an &lt;CODE&gt;epoch&lt;/CODE&gt; time for &lt;CODE&gt;OldTime&lt;/CODE&gt; or it will not work because &lt;CODE&gt;relative_time&lt;/CODE&gt; requires &lt;CODE&gt;epoch&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2015 15:15:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149571#M1448</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-07-30T15:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macros to set time variable</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149572#M1449</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Thanks for your reply. My purpose of setting the macros is to print out the date_time variable to identify the source, which is a filename, named in YYYYMMDDHH. I'm trying to achieve here is to search index=set source=&lt;EM&gt;'ytd1hourago'&lt;/EM&gt; where the ytd11hourago is the macro name for printing out the date which is ytd 1 hour ago. It could be "index-set source=&lt;EM&gt;20150810&lt;/EM&gt;. May I know how can I achieve that through macros?&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;

&lt;P&gt;Leon&lt;/P&gt;</description>
      <pubDate>Sun, 02 Aug 2015 03:54:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149572#M1449</guid>
      <dc:creator>leonheart78</dc:creator>
      <dc:date>2015-08-02T03:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macros to set time variable</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149573#M1450</link>
      <description>&lt;P&gt;OK, then my answer stands, except that (if I undersand you correctly), you would use it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=set [| noop | stats count | `TimeLessOneHour(now(), source)` | fields source]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will normalize down to a search string that says this (but the date will obviously be different):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=set source=20150810
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Aug 2015 14:11:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-use-macros-to-set-time-variable/m-p/149573#M1450</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-02T14:11:36Z</dc:date>
    </item>
  </channel>
</rss>

