<?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: How to get time picker earliest and latest in epoch with JavaScript? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-time-picker-earliest-and-latest-in-epoch-with/m-p/632150#M51823</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/146503"&gt;@fredclown&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think there is no simple way to get epoch values from the timerange picker but I have another calculated way.&lt;/P&gt;&lt;P&gt;You can execute the below search and get epoch time.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | addinfo | table info_min_time info_max_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two ways to execute this search.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&amp;nbsp;from dashboard XML&lt;/LI&gt;&lt;LI&gt;from Javascript&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Check the below link for the first way.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374299" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374299&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You will have the epoch time in the `tokEarliest` and `tokLatest` tokens. Just need to access it from Javascript.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Check the below solution for the second way.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
        'underscore',
        'jquery',
        'splunkjs/mvc',
        'splunkjs/mvc/simplexml/ready!'
      ], function(_, $, mvc) {
        console.log("taskCollectionTable");
              
              var earliestEpoch;
              var latestEpoch;
      
      
              var SearchManager = require("splunkjs/mvc/searchmanager");
              // Create the search manager
              var mysearch =  new SearchManager({
                      // id: "search1",
                      app: "search",
                      earliest_time: "$timePicker.earliest$",
                      latest_time: "$timePicker.latest$",
                      search: "| makeresults | addinfo | table info_min_time info_max_time"
              }, {tokens: true});
      
              mysearch.on('search:done', function(properties) {
                      var myResults = mysearch.data("results");
                      myResults.on("data", function () { 
                              resultArray = myResults.data().rows;
                              earliestEpoch = resultArray[0][0];
                              latestEpoch = resultArray[0][0];
      
                              console.log("earliestEpoch", earliestEpoch);
                              console.log("latestEpoch", latestEpoch);
                      });
      
              });

});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Feb 2023 07:41:09 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2023-02-24T07:41:09Z</dc:date>
    <item>
      <title>How to get time picker earliest and latest in epoch with JavaScript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-time-picker-earliest-and-latest-in-epoch-with/m-p/624739#M51223</link>
      <description>&lt;P&gt;I have a simple xml dashboard that I am doing some custom JavaScript with. I would like to get the earliest and latest from the time picker. However, if the time picker is set to today I am getting "@d" for the earliest and "now" for the latest. Are there any helper functions to convert relative time to epoch? You can see this in my simplified code example below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;...
var defaultTokens = mvc.Components.get("default");

var earliest = defaultTokens.get('timePicker.earliest'); //when time picker is today this returns @d
var latest = defaultTokens.get('timePicker.latest'); //when time picker is today this returns now
...&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 16:09:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-time-picker-earliest-and-latest-in-epoch-with/m-p/624739#M51223</guid>
      <dc:creator>fredclown</dc:creator>
      <dc:date>2022-12-19T16:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get time picker earliest and latest in epoch with JavaScript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-time-picker-earliest-and-latest-in-epoch-with/m-p/632150#M51823</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/146503"&gt;@fredclown&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think there is no simple way to get epoch values from the timerange picker but I have another calculated way.&lt;/P&gt;&lt;P&gt;You can execute the below search and get epoch time.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | addinfo | table info_min_time info_max_time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two ways to execute this search.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&amp;nbsp;from dashboard XML&lt;/LI&gt;&lt;LI&gt;from Javascript&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;STRONG&gt;Check the below link for the first way.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374299" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Converting-relative-time-into-epoch-for-the-time-range-picker/m-p/374299&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You will have the epoch time in the `tokEarliest` and `tokLatest` tokens. Just need to access it from Javascript.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Check the below solution for the second way.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
        'underscore',
        'jquery',
        'splunkjs/mvc',
        'splunkjs/mvc/simplexml/ready!'
      ], function(_, $, mvc) {
        console.log("taskCollectionTable");
              
              var earliestEpoch;
              var latestEpoch;
      
      
              var SearchManager = require("splunkjs/mvc/searchmanager");
              // Create the search manager
              var mysearch =  new SearchManager({
                      // id: "search1",
                      app: "search",
                      earliest_time: "$timePicker.earliest$",
                      latest_time: "$timePicker.latest$",
                      search: "| makeresults | addinfo | table info_min_time info_max_time"
              }, {tokens: true});
      
              mysearch.on('search:done', function(properties) {
                      var myResults = mysearch.data("results");
                      myResults.on("data", function () { 
                              resultArray = myResults.data().rows;
                              earliestEpoch = resultArray[0][0];
                              latestEpoch = resultArray[0][0];
      
                              console.log("earliestEpoch", earliestEpoch);
                              console.log("latestEpoch", latestEpoch);
                      });
      
              });

});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 07:41:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-time-picker-earliest-and-latest-in-epoch-with/m-p/632150#M51823</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2023-02-24T07:41:09Z</dc:date>
    </item>
  </channel>
</rss>

