<?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: Set given preset value in time range picker in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458081#M129379</link>
    <description>&lt;P&gt;I've found a solution: the default value of the dat/time picker has to be &lt;STRONG&gt;Previous week&lt;/STRONG&gt;. See the code below. In addition in its &lt;STRONG&gt;change&lt;/STRONG&gt; section it contains code which converts the earliest and latest values to human readable form (&lt;STRONG&gt;earliest_str&lt;/STRONG&gt; and &lt;STRONG&gt;latest_str&lt;/STRONG&gt;).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;input type="time" token="range" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Set Date/Time Range&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;Previous week&amp;lt;/default&amp;gt;
      &amp;lt;change&amp;gt;
        &amp;lt;eval token="earliest_tok"&amp;gt;if(isnum($range.earliest$), $range.earliest$, relative_time(now(), $range.earliest$))&amp;lt;/eval&amp;gt;
        &amp;lt;eval token="latest_tok"&amp;gt;if(isnull($range.latest$), now(), if(isnum($range.latest$), $range.latest$, relative_time(now(), $range.latest$)))&amp;lt;/eval&amp;gt;
        &amp;lt;eval token="earliest_str"&amp;gt;strftime($earliest_tok$, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
        &amp;lt;eval token="latest_str"&amp;gt;strftime($latest_tok$ - 1, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
      &amp;lt;/change&amp;gt;
    &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In order to have right &lt;STRONG&gt;earliest_str&lt;/STRONG&gt; and &lt;STRONG&gt;latest_str&lt;/STRONG&gt; just after opening the dashboard we have to initialize them in the &lt;STRONG&gt;init&lt;/STRONG&gt; section of the dashboard:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;init&amp;gt;
    &amp;lt;eval token="earliest_tok"&amp;gt;relative_time(now(), "-7d@w0")&amp;lt;/eval&amp;gt;
    &amp;lt;eval token="latest_tok"&amp;gt;relative_time(now(), "@w0")&amp;lt;/eval&amp;gt;
    &amp;lt;eval token="earliest_str"&amp;gt;strftime($earliest_tok$, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
    &amp;lt;eval token="latest_str"&amp;gt;strftime($latest_tok$ - 1, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
  &amp;lt;/init&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this &lt;STRONG&gt;init&lt;/STRONG&gt; section the relative date format is to be used: &lt;STRONG&gt;"-7d@w0"&lt;/STRONG&gt; and &lt;STRONG&gt;"@w0"&lt;/STRONG&gt; which is equivalent to &lt;STRONG&gt;Previous week&lt;/STRONG&gt; default value of the date/time picker input control.&lt;/P&gt;</description>
    <pubDate>Tue, 14 May 2019 09:21:17 GMT</pubDate>
    <dc:creator>fjp2485</dc:creator>
    <dc:date>2019-05-14T09:21:17Z</dc:date>
    <item>
      <title>Set given preset value in time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458078#M129376</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm using Splunk Enterprise 7.2.3.&lt;BR /&gt;
I have a time range picker on my dashboard to set the date/time range to search between. I want to set its default value to "Previous week". In the XML code of the dashboard I can calculate the required date range and I can set that in the time range picker also (and it works well), but the displayed preset value will be: "Between Date-times". But I want to show: "Previous week". How can I do it?&lt;/P&gt;

&lt;P&gt;Thanks in advance,&lt;BR /&gt;
fjp2485&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 12:08:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458078#M129376</guid>
      <dc:creator>fjp2485</dc:creator>
      <dc:date>2019-05-13T12:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Set given preset value in time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458079#M129377</link>
      <description>&lt;P&gt;In your dashboard xml, update the stanza for &lt;CODE&gt;time&lt;/CODE&gt; input to use following relative time range:&lt;BR /&gt;
&lt;STRONG&gt;Updated&lt;/STRONG&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;earliest&amp;gt;-7d@w0&amp;lt;/earliest&amp;gt;
&amp;lt;latest&amp;gt;@w0&amp;lt;/latest&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 May 2019 14:13:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458079#M129377</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-05-13T14:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Set given preset value in time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458080#M129378</link>
      <description>&lt;P&gt;Hi somesoni2,&lt;/P&gt;

&lt;P&gt;Thanks for your answer.&lt;BR /&gt;
You probably meant -1w@w0 instead of -7w, isn't it?&lt;/P&gt;

&lt;P&gt;So the complete input section supposed to look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;input type="time" token="range" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Set Date/Time Range&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;
        &amp;lt;earliest&amp;gt;-1w@w0&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;@w0&amp;lt;/latest&amp;gt;
      &amp;lt;/default&amp;gt;
    &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Unfortunately the displayed text is "Custom time", see screenshot below:&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/7059i9EBEFB7D8E3601C0/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;But my specification prescribes to show: "Previous week" because this text is more informative for the user.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 07:44:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458080#M129378</guid>
      <dc:creator>fjp2485</dc:creator>
      <dc:date>2019-05-14T07:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Set given preset value in time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458081#M129379</link>
      <description>&lt;P&gt;I've found a solution: the default value of the dat/time picker has to be &lt;STRONG&gt;Previous week&lt;/STRONG&gt;. See the code below. In addition in its &lt;STRONG&gt;change&lt;/STRONG&gt; section it contains code which converts the earliest and latest values to human readable form (&lt;STRONG&gt;earliest_str&lt;/STRONG&gt; and &lt;STRONG&gt;latest_str&lt;/STRONG&gt;).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;input type="time" token="range" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Set Date/Time Range&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;Previous week&amp;lt;/default&amp;gt;
      &amp;lt;change&amp;gt;
        &amp;lt;eval token="earliest_tok"&amp;gt;if(isnum($range.earliest$), $range.earliest$, relative_time(now(), $range.earliest$))&amp;lt;/eval&amp;gt;
        &amp;lt;eval token="latest_tok"&amp;gt;if(isnull($range.latest$), now(), if(isnum($range.latest$), $range.latest$, relative_time(now(), $range.latest$)))&amp;lt;/eval&amp;gt;
        &amp;lt;eval token="earliest_str"&amp;gt;strftime($earliest_tok$, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
        &amp;lt;eval token="latest_str"&amp;gt;strftime($latest_tok$ - 1, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
      &amp;lt;/change&amp;gt;
    &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In order to have right &lt;STRONG&gt;earliest_str&lt;/STRONG&gt; and &lt;STRONG&gt;latest_str&lt;/STRONG&gt; just after opening the dashboard we have to initialize them in the &lt;STRONG&gt;init&lt;/STRONG&gt; section of the dashboard:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;init&amp;gt;
    &amp;lt;eval token="earliest_tok"&amp;gt;relative_time(now(), "-7d@w0")&amp;lt;/eval&amp;gt;
    &amp;lt;eval token="latest_tok"&amp;gt;relative_time(now(), "@w0")&amp;lt;/eval&amp;gt;
    &amp;lt;eval token="earliest_str"&amp;gt;strftime($earliest_tok$, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
    &amp;lt;eval token="latest_str"&amp;gt;strftime($latest_tok$ - 1, "%Y.%m.%d")&amp;lt;/eval&amp;gt;
  &amp;lt;/init&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In this &lt;STRONG&gt;init&lt;/STRONG&gt; section the relative date format is to be used: &lt;STRONG&gt;"-7d@w0"&lt;/STRONG&gt; and &lt;STRONG&gt;"@w0"&lt;/STRONG&gt; which is equivalent to &lt;STRONG&gt;Previous week&lt;/STRONG&gt; default value of the date/time picker input control.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 09:21:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458081#M129379</guid>
      <dc:creator>fjp2485</dc:creator>
      <dc:date>2019-05-14T09:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Set given preset value in time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458082#M129380</link>
      <description>&lt;P&gt;That was a typo on my side. I wanted to use &lt;CODE&gt;-7d@w0&lt;/CODE&gt;.  Also, I'm assuming you're launching the dashboard fresh (from navigation menu) after making change so that it's using the default values of the time range picker.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 14:55:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Set-given-preset-value-in-time-range-picker/m-p/458082#M129380</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-05-14T14:55:09Z</dc:date>
    </item>
  </channel>
</rss>

