<?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: Converting relative time into epoch for the time range picker in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374303#M110028</link>
    <description>&lt;P&gt;Great solution!&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2018 17:28:26 GMT</pubDate>
    <dc:creator>isanchez</dc:creator>
    <dc:date>2018-01-03T17:28:26Z</dc:date>
    <item>
      <title>Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374299#M110024</link>
      <description>&lt;P&gt;Good day,&lt;/P&gt;

&lt;P&gt;Recently, I worked on a project that required me to set up a way for users to retrieve records from SQL with varying dates.  I was able to  set it up to run so that they can pick explicit dates to search between with an eval statement:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[dbxquery here] | eval submitdate_epoch=strptime(submit_date, "%Y-%m-%d %H:%M:%S.%N") | search submitdate_epoch&amp;gt;=$timetok1.earliest$ AND submitdate_epoch&amp;lt;=$timetok1.latest$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, to make things easier for the user, I'd like to also include a way to pass relative time into the search, such as "now" or "7 days ago".  Is there any way to do this, and if so, can you point me towards it?&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 14:03:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374299#M110024</guid>
      <dc:creator>Svill321</dc:creator>
      <dc:date>2017-08-21T14:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374300#M110025</link>
      <description>&lt;P&gt;Since Time Token change event does not handle tokens for time, following is the workaround to achieve this:&lt;/P&gt;

&lt;P&gt;1) Create Time input token with token name as &lt;CODE&gt;timetok1&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="time" token="timetok1" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
      &amp;lt;default&amp;gt;
        &amp;lt;earliest&amp;gt;-5m&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;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2) Add a dummy search to get time input tokens &lt;CODE&gt;$timetok1.earliest$&lt;/CODE&gt; and &lt;CODE&gt;$timetok1.latest$&lt;/CODE&gt;. Then access the default search handler tokens &lt;CODE&gt;$job.earliesTime$&lt;/CODE&gt; and &lt;CODE&gt;$job.latestTime$&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;|makeresults
    &amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;$timetok1.earliest$&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;$timetok1.latest$&amp;lt;/latest&amp;gt;
    &amp;lt;progress&amp;gt;
      &amp;lt;eval token="tokEarliest"&amp;gt;strptime($job.earliestTime$,"%Y-%m-%dT%H:%M:%S.%3N%z")&amp;lt;/eval&amp;gt;
      &amp;lt;eval token="tokLatest"&amp;gt;strptime($job.latestTime$,"%Y-%m-%dT%H:%M:%S.%3N%z")&amp;lt;/eval&amp;gt;
    &amp;lt;/progress&amp;gt;
  &amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Use &lt;CODE&gt;eval&lt;/CODE&gt; tag to convert String time to Epoch using &lt;CODE&gt;strptime()&lt;/CODE&gt;&lt;BR /&gt;
3) Use tokens &lt;CODE&gt;tokEarliest&lt;/CODE&gt; and &lt;CODE&gt;tokLatest&lt;/CODE&gt; in your other searches in the dashboard which are epoch time.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 15:24:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374300#M110025</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-21T15:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374301#M110026</link>
      <description>&lt;P&gt;This worked beautifully.  Thank you so much!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 17:06:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374301#M110026</guid>
      <dc:creator>Svill321</dc:creator>
      <dc:date>2017-08-21T17:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374302#M110027</link>
      <description>&lt;P&gt;Anytime! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 17:20:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374302#M110027</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-21T17:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374303#M110028</link>
      <description>&lt;P&gt;Great solution!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 17:28:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374303#M110028</guid>
      <dc:creator>isanchez</dc:creator>
      <dc:date>2018-01-03T17:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374304#M110029</link>
      <description>&lt;P&gt;Great solution!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 17:29:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374304#M110029</guid>
      <dc:creator>isanchez</dc:creator>
      <dc:date>2018-01-03T17:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374305#M110030</link>
      <description>&lt;P&gt;I have been looking for this answer for about 3 hours today.  Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 18:16:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374305#M110030</guid>
      <dc:creator>gt_dev</dc:creator>
      <dc:date>2018-07-20T18:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374306#M110031</link>
      <description>&lt;P&gt;I had updated my answer with two approaches (on similar idea of using an independent search as mentioned above). Please refer to that as well.&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, 20 Jul 2018 21:15:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374306#M110031</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-07-20T21:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374307#M110032</link>
      <description>&lt;P&gt;@niketnilay Thank you so much. Your solution is very elegant. &lt;/P&gt;

&lt;P&gt;Is there a way to do this from an independent search window as opposed to within a dashboard ?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 14:07:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374307#M110032</guid>
      <dc:creator>kkrishnan_splun</dc:creator>
      <dc:date>2018-10-19T14:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting relative time into epoch for the time range picker</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374308#M110033</link>
      <description>&lt;P&gt;@kkrishnan_splunk kkrishnanthe possibility would be to use &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | makeresults
  | fields - _time
  | addinfo
  | fields info_min_time, info_max_time
   | map search="&amp;lt;yourActualSearchWith$info_min_time$And$info_max_time$&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If this does not work or help please explain a bit more on your use case.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 03:35:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374308#M110033</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-10-21T03:35:12Z</dc:date>
    </item>
  </channel>
</rss>

