<?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: Macro with eval-based definition submacro to set earliest and latest in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75931#M742</link>
    <description>&lt;P&gt;Don't blame strptime for that, just enclose $day$ in quotes. Else you end up computing 2013-03-27 as 1983.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2013 12:58:53 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2013-03-27T12:58:53Z</dc:date>
    <item>
      <title>Macro with eval-based definition submacro to set earliest and latest</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75928#M739</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;i need a macro that acceppts a day and converts that into a format to it can be used in earliest and latest inside.&lt;BR /&gt;
My idea:&lt;/P&gt;

&lt;P&gt;createReport(1)&lt;BR /&gt;
param: 'day', format='yyyy-MM-dd'&lt;BR /&gt;
search=foo bar error NOT warning earliest=&lt;CODE&gt;parseDayForEarliest($day$)&lt;/CODE&gt; latest=&lt;CODE&gt;parseDayForLatest($day$)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;parseDayForEarliest(1)&lt;BR /&gt;
param: 'day', format='yyyy-MM-dd'&lt;BR /&gt;
strftime(strptime($day$,"%Y-%M-%d")-86400,"%m/%d/%Y:%H:%M:%S")&lt;/P&gt;

&lt;P&gt;parseDayForLatest(1)&lt;BR /&gt;
param: 'day', format='yyyy-MM-dd'&lt;BR /&gt;
strftime(strptime($day$,"%Y-%M-%d"),"%m/%d/%Y:%H:%M:%S")&lt;/P&gt;

&lt;P&gt;But it does not work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Regards, Jens&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2013 10:27:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75928#M739</guid>
      <dc:creator>JensT</dc:creator>
      <dc:date>2013-03-27T10:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with eval-based definition submacro to set earliest and latest</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75929#M740</link>
      <description>&lt;P&gt;First of all, %M is minute - you need %m for month.&lt;/P&gt;

&lt;P&gt;That's not the main problem though... you cannot write earliest=some_function(...). You need to move that to a subsearch like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[stats count | eval earliest=relative_time(strptime("$day$","%Y-%m-%d"), "-d") | return earliest] [stats count | eval latest=strptime("$day$","%Y-%m-%d") | return latest]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Those subsearches can now be moved into a macro.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2013 10:49:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75929#M740</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-03-27T10:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with eval-based definition submacro to set earliest and latest</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75930#M741</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;thanks for the answer and the correction for the strptime.&lt;/P&gt;

&lt;P&gt;Your solution might work, but I disagree that i &lt;EM&gt;need&lt;/EM&gt; to do it like this.&lt;BR /&gt;
eval-based-defintion macros can be used here. Its just that i have problems to return the output as string. Tests are working fine with simple things, but not with strptime.&lt;/P&gt;

&lt;P&gt;Regards, Jens&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2013 12:34:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75930#M741</guid>
      <dc:creator>JensT</dc:creator>
      <dc:date>2013-03-27T12:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with eval-based definition submacro to set earliest and latest</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75931#M742</link>
      <description>&lt;P&gt;Don't blame strptime for that, just enclose $day$ in quotes. Else you end up computing 2013-03-27 as 1983.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2013 12:58:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75931#M742</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-03-27T12:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with eval-based definition submacro to set earliest and latest</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75932#M743</link>
      <description>&lt;P&gt;Martin: It was that simple. I just was missing the quotes in the submacro.&lt;/P&gt;

&lt;P&gt;In the main macro:&lt;BR /&gt;
earliest=&lt;CODE&gt;parseDayForEarliest("2013-03-13")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;parseDayForEarliest(1)&lt;BR /&gt;
strftime(strptime("$day$","%Y-%m-%d"),"%m/%d/%Y:%H:%M:%S")&lt;BR /&gt;
eval-based defintion on.&lt;/P&gt;

&lt;P&gt;Regards, Jens&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2013 16:58:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macro-with-eval-based-definition-submacro-to-set-earliest-and/m-p/75932#M743</guid>
      <dc:creator>JensT</dc:creator>
      <dc:date>2013-03-27T16:58:24Z</dc:date>
    </item>
  </channel>
</rss>

