<?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: Use timepicker earliest and latest as epoch time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/507541#M141896</link>
    <description>&lt;P&gt;Simple, elegant, and still valid 3 years later!&amp;nbsp; Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jul 2020 12:57:50 GMT</pubDate>
    <dc:creator>andrewtrobec</dc:creator>
    <dc:date>2020-07-06T12:57:50Z</dc:date>
    <item>
      <title>Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365847#M107888</link>
      <description>&lt;P&gt;I have the same problem as in the link below:&lt;/P&gt;

&lt;P&gt;[&lt;A href="https://answers.splunk.com/answers/336929/how-can-i-get-time-picker-earliest-and-latest-epoc.html?utm_source=typeahead&amp;amp;utm_medium=newquestion&amp;amp;utm_campaign=no_votes_sort_relev%5D%5B1"&gt;https://answers.splunk.com/answers/336929/how-can-i-get-time-picker-earliest-and-latest-epoc.html?utm_source=typeahead&amp;amp;utm_medium=newquestion&amp;amp;utm_campaign=no_votes_sort_relev][1&lt;/A&gt;]&lt;/P&gt;

&lt;P&gt;Where i need the times to be either human-formatted (Y-M-D H:M:S) or epoch (1510317953) .&lt;/P&gt;

&lt;P&gt;However when i do a search that relies on the timepicker.earliest and latest values I get an error.&lt;BR /&gt;
My search query is &lt;CODE&gt;... | where _time &amp;gt; $time.earliest$ AND _time &amp;lt; $time.latest$&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This gives the  &lt;CODE&gt;Error in 'where' command: The operator at 'd@d  AND _time &amp;lt; now ' is invalid.&lt;/CODE&gt;    &lt;/P&gt;

&lt;P&gt;as we can see the timepicker defaults the 30 days earliest and latest values to &lt;CODE&gt;-30d@d&lt;/CODE&gt; and &lt;CODE&gt;now&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Speed is kind of of the essence here so I need a way to format the input values from the timepicker or to allow the search to accept the specific formats the timepicker gives me. &lt;/P&gt;

&lt;P&gt;Also a random question; why isn't this being  done automatically.. Seems very inefficient to keep converting every event between epoch, human readable and other arbitrary splunk time formats.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 12:49:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365847#M107888</guid>
      <dc:creator>christoffertoft</dc:creator>
      <dc:date>2017-11-10T12:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365848#M107889</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Can you please try this one??&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH |  addinfo| where _time &amp;gt; info_min_time AND _time &amp;lt; info_max_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used &lt;CODE&gt;addinfo&lt;/CODE&gt; command for earliest &amp;amp; latest time. Please check below link for more info.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Addinfo"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Addinfo&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 13:04:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365848#M107889</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-10T13:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365849#M107890</link>
      <description>&lt;P&gt;@kamlesh_vaghela's answer should work. Here is another solution that will give you two tokens you can use anywhere.&lt;/P&gt;

&lt;P&gt;Basically, update the timepicker XML to include a &lt;CODE&gt;change&lt;/CODE&gt; element that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;input type="time" token="time"&amp;gt;
      ...
      &amp;lt;change&amp;gt;
        &amp;lt;eval token="time.earliest_epoch"&amp;gt;if(isnum('earliest'),'earliest',relative_time(now(),'earliest')&amp;lt;/eval&amp;gt;
        &amp;lt;eval token="time.latest_epoch"&amp;gt;if(isnum('latest'),'latest',relative_time(now(),'latest')&amp;lt;/eval&amp;gt;
      &amp;lt;/change&amp;gt;
    &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will give you the tokens &lt;CODE&gt;time.earliest_epoch&lt;/CODE&gt; and &lt;CODE&gt;time.latest_epoch&lt;/CODE&gt; that you can use for the filtering:  &lt;CODE&gt;... | where _time &amp;gt; $time.earliest_epoch$ AND _time &amp;lt; $time.latest_epoch$&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 13:18:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365849#M107890</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-11-10T13:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365850#M107891</link>
      <description>&lt;P&gt;@christoffertoft, refer to two options of getting earliest and latest time from Time Picker using dummy search i.e. &lt;/P&gt;

&lt;P&gt;1) &lt;CODE&gt;addinfo&lt;/CODE&gt; and &lt;BR /&gt;
2) &lt;CODE&gt;$job.earliestTime$&lt;/CODE&gt; and &lt;CODE&gt;$job.latestTime$&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/578984/running-one-of-two-searches-based-on-time-picker-s.html"&gt;https://answers.splunk.com/answers/578984/running-one-of-two-searches-based-on-time-picker-s.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 13:42:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365850#M107891</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-10T13:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365851#M107892</link>
      <description>&lt;P&gt;This does not work unfortunately. The data i pull using a base search is accelerated and indexed from 0 to +infinity. As such, any events have the infity or 0.0000 values for their mix and max times respectively.&lt;/P&gt;

&lt;P&gt;I have gotten the time as &lt;CODE&gt;|eval _time=report_date&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;but the events stretch from 0 to infinity. This means i need to be able to use the timepicker to only chose events where the report_date (_time) are in the range selected in the timepicker.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:45:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365851#M107892</guid>
      <dc:creator>christoffertoft</dc:creator>
      <dc:date>2020-09-29T16:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365852#M107893</link>
      <description>&lt;P&gt;Hi, and thank you very much for your help. @kamlesh_vaghela's answer does not work (please see my reply above). I will try your approach next to see if it works.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 14:05:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365852#M107893</guid>
      <dc:creator>christoffertoft</dc:creator>
      <dc:date>2017-11-10T14:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365853#M107894</link>
      <description>&lt;P&gt;Hi, and thanks for your reply. This unfortunately does not work. See the comment i posted to @kamlesh_vaghela's answer.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 14:06:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365853#M107894</guid>
      <dc:creator>christoffertoft</dc:creator>
      <dc:date>2017-11-10T14:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365854#M107895</link>
      <description>&lt;P&gt;HI @christoffertoft,&lt;/P&gt;

&lt;P&gt;A missed search in "All Time". Can you please try below search ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH |  addinfo | where ((NOT (isnum(info_max_time) AND info_max_time!="+Infinity")) OR _time &amp;gt; info_min_time AND _time &amp;lt; info_max_time) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 14:09:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365854#M107895</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-10T14:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365855#M107896</link>
      <description>&lt;P&gt;Hi, your approach with converting the values to epoch times seems to have worked. Can you explain the logic behind it?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 14:21:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365855#M107896</guid>
      <dc:creator>christoffertoft</dc:creator>
      <dc:date>2017-11-10T14:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365856#M107897</link>
      <description>&lt;P&gt;As of Splunk 6.3, many of the form inputs can be extended to set / unset / eval tokens based on other tokens or their new values. So this answer looks at the new value of the timepicker whenever it changes, and figures out how to convert that value to epoch time. The &lt;CODE&gt;isnum&lt;/CODE&gt; function in the first condition checks to see if the new time values is already in epoch time form. If it is false, that means the timepicker value is set to a relative time (like &lt;CODE&gt;-30d@d&lt;/CODE&gt;), the the &lt;CODE&gt;relative_time&lt;/CODE&gt; function converts that to epoch time.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 14:53:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365856#M107897</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-11-10T14:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365857#M107898</link>
      <description>&lt;P&gt;Epic, thanks alot. It was the final piece in the puzzle for my dashboard. Credits to you!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 14:56:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365857#M107898</guid>
      <dc:creator>christoffertoft</dc:creator>
      <dc:date>2017-11-10T14:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365858#M107899</link>
      <description>&lt;P&gt;@christoffertoft, the option with &lt;CODE&gt;job.earliestTime&lt;/CODE&gt; and &lt;CODE&gt;job.latestTime&lt;/CODE&gt; should have worked. I am not sure if you tried. I was able to display results for All Time using tokens those two as earliest and latest:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://wiki.splunk.com/images/e/e8/All_Time_Search_using_tokens_from_Time_Picker.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Following is the additional code I used to test&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;chart&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;index=_internal sourcetype=splunkd
| timechart count
        &amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;$tokEarliestTime1$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;$tokLatestTime1$&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="charting.chart"&amp;gt;column&amp;lt;/option&amp;gt;
      &amp;lt;/chart&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But no need to stress as you already have an working solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 15:36:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/365858#M107899</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-10T15:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Use timepicker earliest and latest as epoch time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/507541#M141896</link>
      <description>&lt;P&gt;Simple, elegant, and still valid 3 years later!&amp;nbsp; Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 12:57:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-timepicker-earliest-and-latest-as-epoch-time/m-p/507541#M141896</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2020-07-06T12:57:50Z</dc:date>
    </item>
  </channel>
</rss>

