<?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: Dashboard: How can I convert a token from a &amp;quot;Time Picker&amp;quot; into a unit of time like minutes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209702#M61323</link>
    <description>&lt;P&gt;I think earliest and latest should be enclosed in $ since they are tokens. I've used a similar piece of code and that worked for me.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Dec 2016 10:25:51 GMT</pubDate>
    <dc:creator>sgadde</dc:creator>
    <dc:date>2016-12-19T10:25:51Z</dc:date>
    <item>
      <title>Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209696#M61317</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;

&lt;P&gt;Here's the process I'm trying to do.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Initial Conversion&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;1.&lt;/STRONG&gt; Use a "Time Picker" input &lt;STRONG&gt;--&amp;gt;&lt;/STRONG&gt; &lt;BR /&gt;
&lt;STRONG&gt;2.&lt;/STRONG&gt; Take the time selected &lt;STRONG&gt;--&amp;gt;&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;3.&lt;/STRONG&gt;  Convert that into a token that stores the value in minutes&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Example &amp;amp; Usage of the Token&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;1.&lt;/STRONG&gt; User selects desired selection from the time picker input &lt;STRONG&gt;--&amp;gt;&lt;/STRONG&gt; &lt;BR /&gt;
&lt;EM&gt;ex: Selected time is "last 4 hours"&lt;/EM&gt;&lt;BR /&gt;
&lt;STRONG&gt;2.&lt;/STRONG&gt; a token is then given the value in minutes&lt;BR /&gt;
 &lt;EM&gt;ex: $sel_time$ = 240&lt;/EM&gt; &lt;STRONG&gt;--&amp;gt;&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;3.&lt;/STRONG&gt; use the token inside a custom time frame &lt;BR /&gt;
ex: 7d-$sel_time$&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;I'm not sure how the time picker is formatted or stored, so I'm having trouble. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 19:43:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209696#M61317</guid>
      <dc:creator>danielbarr</dc:creator>
      <dc:date>2016-08-02T19:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209697#M61318</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="time" token="t" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;
        &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
      &amp;lt;/default&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;index=_internal | head 1 | eval x=strftime(relative_time(now(), "$t.earliest$"), "%c") | table _time x&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-15m&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;row&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Aug 2016 20:23:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209697#M61318</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-02T20:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209698#M61319</link>
      <description>&lt;P&gt;I'm not sure how to use this for my case. All I want is the timespan selected in minutes, not the formatted date. So if they select 60 minutes the token would just be $sel_timespan$ = 60. Maybe I'm misunderstanding what you did here.&lt;/P&gt;

&lt;P&gt;I think I'd have to take the two time periods your code gives and then subtract them to get the time in minutes.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 13:33:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209698#M61319</guid>
      <dc:creator>danielbarr</dc:creator>
      <dc:date>2016-08-03T13:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209699#M61320</link>
      <description>&lt;PRE&gt;&lt;/PRE&gt;
  

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;input type="time" searchWhenChanged="true"&amp;gt;
  &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
  &amp;lt;default&amp;gt;
    &amp;lt;earliest&amp;gt;-7d@w0&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;@w0&amp;lt;/latest&amp;gt;
  &amp;lt;/default&amp;gt;
  &amp;lt;change&amp;gt;
    &amp;lt;condition match="isnum($earliest$) OR isnum($latest$)"&amp;gt;
      &amp;lt;eval token="sel_time"&amp;gt;tostring(($latest$-$earliest$)/60)+"m"&amp;lt;/eval&amp;gt;
    &amp;lt;/condition&amp;gt;
    &amp;lt;condition&amp;gt;
      &amp;lt;eval token="sel_time"&amp;gt;tostring((relative_time(now(), $latest$)-relative_time(now(), $earliest$))/60)+"m"&amp;lt;/eval&amp;gt;
    &amp;lt;/condition&amp;gt;
  &amp;lt;/change&amp;gt;
&amp;lt;/input&amp;gt;


&amp;lt;panel&amp;gt;
  &amp;lt;table&amp;gt;
    &amp;lt;title&amp;gt;$sel_time$&amp;lt;/title&amp;gt;
    &amp;lt;search&amp;gt;
      &amp;lt;query&amp;gt;index=_internal | head 1 |eval minutes=$sel_time|s$ , earliest=$earliest|s$, latest=$latest|s$ | table earliest, latest, minutes&amp;lt;/query&amp;gt;
      &amp;lt;earliest&amp;gt;$earliest$&amp;lt;/earliest&amp;gt;
      &amp;lt;latest&amp;gt;$earliest$&amp;lt;/latest&amp;gt;
    &amp;lt;/search&amp;gt;
    &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
    &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
    &amp;lt;option name="drilldown"&amp;gt;row&amp;lt;/option&amp;gt;
    &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
    &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
  &amp;lt;/table&amp;gt;
&amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will create a new token,&lt;STRONG&gt;&lt;EM&gt;sel_time&lt;/EM&gt;&lt;/STRONG&gt;, which calculates the minutes contained in the time range. &lt;BR /&gt;
Time picker gives you &lt;STRONG&gt;&lt;EM&gt;earliest&lt;/EM&gt;&lt;/STRONG&gt; and &lt;STRONG&gt;&lt;EM&gt;latest&lt;/EM&gt;&lt;/STRONG&gt; tokens in epoch/Unix timestamp  ( if you select date range or specify date/time explicilty) or in string format like "-7d@w0" (if you select relative time range presets).&lt;/P&gt;

&lt;P&gt;Logic: &lt;STRONG&gt;&lt;EM&gt;sel_time&lt;/EM&gt;&lt;/STRONG&gt; token is set based on the type of earliest and latest. &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;If both are numeric, &lt;STRONG&gt;&lt;EM&gt;sel_time&lt;/EM&gt;&lt;/STRONG&gt; token is the difference between the epoch provided by the &lt;STRONG&gt;&lt;EM&gt;latest&lt;/EM&gt;&lt;/STRONG&gt; and &lt;STRONG&gt;&lt;EM&gt;earliest&lt;/EM&gt;&lt;/STRONG&gt; tokens of your time picker input divided by 60. &lt;/LI&gt;
&lt;LI&gt;For all other cases, &lt;STRONG&gt;&lt;EM&gt;latest&lt;/EM&gt;&lt;/STRONG&gt; and &lt;STRONG&gt;&lt;EM&gt;earliest&lt;/EM&gt;&lt;/STRONG&gt; tokens are converted to epoch and the difference in seconds is divided by 60 and stored in &lt;STRONG&gt;&lt;EM&gt;sel_time&lt;/EM&gt;&lt;/STRONG&gt; token.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;In your question: 3. use the token inside a custom time frame ex: 7d-$sel_time$, your $sel_time$ should have m at the end to specify that the value given by $sel_time$ is in minutes.&lt;/P&gt;

&lt;P&gt;Here the string conversion and the concatenation of "m" at the end is done so &lt;EM&gt;sel_time&lt;/EM&gt; token can be used along with relative time presets without modification.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:49:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209699#M61320</guid>
      <dc:creator>sgadde</dc:creator>
      <dc:date>2020-09-29T10:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209700#M61321</link>
      <description>&lt;P&gt;You could do &lt;CODE&gt;eval e=relative_time(now(), "$t.earliest$" | eval l=relative_time(now(), "$t.latest$" | eval dur=l-e&lt;/CODE&gt; to get the duration&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2016 04:10:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209700#M61321</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-05T04:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209701#M61322</link>
      <description>&lt;P&gt;Thanks! This helped me a lot.&lt;BR /&gt;
But I think you have to change the references to the variables like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;input type="time" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Time Picker&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;
        &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
      &amp;lt;/default&amp;gt;
      &amp;lt;change&amp;gt;
        &amp;lt;condition match="isnum(earliest)"&amp;gt;
          &amp;lt;eval token="sel_time"&amp;gt;tostring((latest-earliest)/60)+"m"&amp;lt;/eval&amp;gt;
        &amp;lt;/condition&amp;gt;
        &amp;lt;condition&amp;gt;
          &amp;lt;eval token="sel_time"&amp;gt;tostring((relative_time(now(), latest)-relative_time(now(), earliest))/60)+"m"&amp;lt;/eval&amp;gt;
        &amp;lt;/condition&amp;gt;
      &amp;lt;/change&amp;gt;
    &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Dec 2016 10:00:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209701#M61322</guid>
      <dc:creator>koenphilipsen</dc:creator>
      <dc:date>2016-12-19T10:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209702#M61323</link>
      <description>&lt;P&gt;I think earliest and latest should be enclosed in $ since they are tokens. I've used a similar piece of code and that worked for me.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2016 10:25:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209702#M61323</guid>
      <dc:creator>sgadde</dc:creator>
      <dc:date>2016-12-19T10:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209703#M61324</link>
      <description>&lt;P&gt;Thanks for this. From my testing I didn't even need the conditional on the isnum.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   &amp;lt;change&amp;gt;
       &amp;lt;eval token="sel_time"&amp;gt;tostring((relative_time(now(), $latest$)-relative_time(now(), $earliest$))/60)+"m"&amp;lt;/eval&amp;gt;
   &amp;lt;/change&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My only issue now is initializing the string. It works great on changes, but init doesn't seem to have the values in the time picker yet.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2017 17:52:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209703#M61324</guid>
      <dc:creator>tmcmaster</dc:creator>
      <dc:date>2017-09-18T17:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard: How can I convert a token from a "Time Picker" into a unit of time like minutes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209704#M61325</link>
      <description>&lt;P&gt;@danielbarr, did you manage to get this working? I am trying to achieve the same think but without great success...&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 16:22:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Dashboard-How-can-I-convert-a-token-from-a-quot-Time-Picker-quot/m-p/209704#M61325</guid>
      <dc:creator>neluvasilica</dc:creator>
      <dc:date>2019-03-27T16:22:54Z</dc:date>
    </item>
  </channel>
</rss>

