<?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 How to dynamically compare two time ranges? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228214#M14136</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;i have a dashboard with panels comparing data of historical data and showing it graphically.&lt;BR /&gt;
i manipulate the _time for all the searches to be in the same time in the panel.&lt;BR /&gt;
example - i take data from today between 10:00-11:00, and data from yesterday between 10:00-11:00.&lt;BR /&gt;
then I manipulate the _time of the second search so that in the panel the two graphs will be on the same &lt;B&gt;time frame&lt;/B&gt;, but they are originally from different &lt;B&gt;dates&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;the problem that i am experiencing is that i want to change the time frame dynamically.&lt;BR /&gt;
i'm doing so using a timepicker.&lt;/P&gt;

&lt;P&gt;this is my timepicker:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fieldset submitButton="false"
   input type="time" token="timeField"
      label:/label
      default
        earliest:-1h:earliest
        latest:now:latest
      default
    input
  fieldset
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$ latest=$timeField.latest$ ID=000 | eval ReportKey="ID0 Today" | append [search index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$-86400 latest=$timeField.latest$-1d@m ID=000 | eval ReportKey="ID0 Yesterday" | eval _time=_time+86400| append [search index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$-604800 latest=$timeField.latest$-7d@m ID=000 | eval ReportKey="ID0 Last week" | eval _time=_time+7*86400 | append [search index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$-2419200 latest=$timeField.latest$-28d@m ID=000 | eval ReportKey="ID0 Last Month" | eval _time=_time+28*86400]]] |  timechart span=1m max(field1) by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this search will work perfect if the time i'm picking in the timepicker is a relative time, for example: Last 1 hour/Last 1 day/etc..&lt;BR /&gt;
but if i'm picking a specific time, for example: &lt;CODE&gt;10/13/2016 09:00:00.000  10/13/2016 10:00:00.000&lt;/CODE&gt; then the search will fail, because i get an epoch time from the second choice.&lt;/P&gt;

&lt;P&gt;how can i overcome this?&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2016 17:15:56 GMT</pubDate>
    <dc:creator>naty</dc:creator>
    <dc:date>2016-11-14T17:15:56Z</dc:date>
    <item>
      <title>How to dynamically compare two time ranges?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228214#M14136</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;i have a dashboard with panels comparing data of historical data and showing it graphically.&lt;BR /&gt;
i manipulate the _time for all the searches to be in the same time in the panel.&lt;BR /&gt;
example - i take data from today between 10:00-11:00, and data from yesterday between 10:00-11:00.&lt;BR /&gt;
then I manipulate the _time of the second search so that in the panel the two graphs will be on the same &lt;B&gt;time frame&lt;/B&gt;, but they are originally from different &lt;B&gt;dates&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;the problem that i am experiencing is that i want to change the time frame dynamically.&lt;BR /&gt;
i'm doing so using a timepicker.&lt;/P&gt;

&lt;P&gt;this is my timepicker:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fieldset submitButton="false"
   input type="time" token="timeField"
      label:/label
      default
        earliest:-1h:earliest
        latest:now:latest
      default
    input
  fieldset
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$ latest=$timeField.latest$ ID=000 | eval ReportKey="ID0 Today" | append [search index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$-86400 latest=$timeField.latest$-1d@m ID=000 | eval ReportKey="ID0 Yesterday" | eval _time=_time+86400| append [search index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$-604800 latest=$timeField.latest$-7d@m ID=000 | eval ReportKey="ID0 Last week" | eval _time=_time+7*86400 | append [search index=myapp source="mysource" NOT DATETIME earliest=$timeField.earliest$-2419200 latest=$timeField.latest$-28d@m ID=000 | eval ReportKey="ID0 Last Month" | eval _time=_time+28*86400]]] |  timechart span=1m max(field1) by ReportKey
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this search will work perfect if the time i'm picking in the timepicker is a relative time, for example: Last 1 hour/Last 1 day/etc..&lt;BR /&gt;
but if i'm picking a specific time, for example: &lt;CODE&gt;10/13/2016 09:00:00.000  10/13/2016 10:00:00.000&lt;/CODE&gt; then the search will fail, because i get an epoch time from the second choice.&lt;/P&gt;

&lt;P&gt;how can i overcome this?&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 17:15:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228214#M14136</guid>
      <dc:creator>naty</dc:creator>
      <dc:date>2016-11-14T17:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare two time ranges?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228215#M14137</link>
      <description>&lt;P&gt;I haven't seen a good way to do this yet. Most people resort to using the Timewrap TA: &lt;A href="https://splunkbase.splunk.com/app/1645/"&gt;https://splunkbase.splunk.com/app/1645/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 18:07:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228215#M14137</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2016-11-14T18:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare two time ranges?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228216#M14138</link>
      <description>&lt;P&gt;hi,&lt;BR /&gt;
thank you for your answer.&lt;BR /&gt;
sadly, i don't have the ability to change the Splunk infrastructure in our business, we can only use it.&lt;BR /&gt;
my problem is with the now() - if the latest is 'now' then all of the searches will work.&lt;BR /&gt;
but, if i'm picking a specific time then i get an EPOCH time, and with EPOCH time i get for example - &lt;BR /&gt;
"invalid latest time 14756941647-1d@m"&lt;/P&gt;

&lt;P&gt;so i need to either change "-1d@m" to EPOCH, or to know when i get "now" or EPOCH for latest time.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 15:54:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228216#M14138</guid>
      <dc:creator>naty</dc:creator>
      <dc:date>2016-12-13T15:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare two time ranges?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228217#M14139</link>
      <description>&lt;P&gt;Add this to the Timepicker control to always return &lt;CODE&gt;epoch&lt;/CODE&gt; time&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="e"&amp;gt;if(isnum($time.earliest$),  relative_time($time.earliest$, "-30d@d), relative_time(relative_time(now(), $time.earliest$), "-30d@d")&amp;lt;/eval&amp;gt;
&amp;lt;/change&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And for you search, your could try this to avoid the sub-searches (append)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo earliest=$e$ | eval ReportKey=case(_time&amp;gt;relative_time(now(), "@d"), "Today", _time&amp;gt;relative_time(now(), "-1d@d") AND _time&amp;lt;relative_time(now(), "@d"), "Yesterday", _time&amp;gt;relative_time(now(), "-30d@d") AND _time&amp;lt;relative_time(now(), "-29d@d"), "Last Month" | ... rest of your query from any one of the segments
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Dec 2016 17:07:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228217#M14139</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-12-13T17:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare two time ranges?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228218#M14140</link>
      <description>&lt;P&gt;hi, thank you!&lt;BR /&gt;
i understood the change to the query to avoid the sub-searches, but i didn't understand the  you added from the time input.&lt;BR /&gt;
why -30d@d? you meant 30 days earlier?&lt;BR /&gt;
can't i just check if time.latest == now?&lt;/P&gt;

&lt;P&gt;also, can you please elaborate on what relative_time does and what it returns? the documentation is not very good about this function..&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 17:27:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228218#M14140</guid>
      <dc:creator>naty</dc:creator>
      <dc:date>2016-12-13T17:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare two time ranges?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228219#M14141</link>
      <description>&lt;P&gt;&lt;CODE&gt;relative_time(x, y)&lt;/CODE&gt; accepts two params. The x represent time value (epoch) and y represents offset from x. For example &lt;CODE&gt;relative_time(now(), "-1h@h")&lt;/CODE&gt; would mean 1 hour prior to now. &lt;/P&gt;

&lt;P&gt;So in query above, -30d represents 30d prior to epoch time selected in the timepicker. &lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2016 18:15:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-dynamically-compare-two-time-ranges/m-p/228219#M14141</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-12-13T18:15:09Z</dc:date>
    </item>
  </channel>
</rss>

