<?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 can we fetch data for specific time interval by comparing time. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337369#M174905</link>
    <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mlc sourcetype=sun_jvm host=27-05-2016-05-27_18_24_42-archive service_name=mxmlc_2016-05-22_20-18-17.gc.log | eval _time = 0 + relative_time | eval earliest_time=strftime(180000,"%Y-%m-%d %H:%M:%S.%3q") | eval latest_time=strftime(183600,"%Y-%m-%d %H:%M:%S.%3q") | table _time, earliest_time, latest_time | where _time &amp;gt;= 180000 AND _time &amp;lt;= 183600
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or, better yet, just put it into the base search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mlc earliest=180000 latest=183600 sourcetype=sun_jvm host=27-05-2016-05-27_18_24_42-archive service_name=mxmlc_2016-05-22_20-18-17.gc.log | eval _time = 0 + relative_time | eval earliest_time=strftime(180000,"%Y-%m-%d %H:%M:%S.%3q") | eval latest_time=strftime(183600,"%Y-%m-%d %H:%M:%S.%3q") | table _time, earliest_time, latest_time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Apr 2017 13:58:24 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-04-18T13:58:24Z</dc:date>
    <item>
      <title>How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337363#M174899</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have  a search query in which I want to display the data for a particular time interval. I have data for 5 days and I want to display only for specific interval (say 1 hrs). &lt;/P&gt;

&lt;P&gt;how can we display data in between earliest and latest time.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/193260-search-query.jpg" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Search Query:&lt;BR /&gt;
eventtype=mlc sourcetype=sun_jvm host=27-05-2016-05-27_18_24_42-archive service_name=mxmlc_2016-05-22_20-18-17.gc.log | eval _time = 0 + relative_time | eval earliest_time=strftime(180000,"%Y-%m-%d %H:%M:%S.%3q") | eval latest_time=strftime(183600,"%Y-%m-%d %H:%M:%S.%3q")  | table _time, earliest_time, latest_time &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:44:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337363#M174899</guid>
      <dc:creator>AKG1_old1</dc:creator>
      <dc:date>2020-09-29T13:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337364#M174900</link>
      <description>&lt;P&gt;Hi agoyal,&lt;BR /&gt;
I'm not sure to had understood your need: do you want a single row with earliest_time and latest_time?&lt;BR /&gt;
if this is your need use something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search
| stats min(_time) AS earliest max(_time) AS latest
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if instead you want to insert two columns with earliest and latest times to your search, you could use appendcols command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search
| appendcols [search your_search | stats min(_time) AS earliest max(_time) AS latest ]
| table your_fields earliest latest
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:54:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337364#M174900</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2020-09-30T02:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337365#M174901</link>
      <description>&lt;P&gt;Hi @cusello,&lt;/P&gt;

&lt;P&gt;Thanks for reply. I dont want single row and also dont want to display earliest and latest time in additional column. &lt;/P&gt;

&lt;P&gt;if you check the screen shot, there is hundrad  of rows with time starting from "1970-01-01 01:00:01.795" to "1970-01-05 23:05:49.357" (5 days data).&lt;/P&gt;

&lt;P&gt;I want to display only those rows which are in between "1970-01-03 03:00:00.000" and "1970-01-03 04:00:00.000". &lt;/P&gt;

&lt;P&gt;Regards&lt;BR /&gt;
Ankit&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 11:52:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337365#M174901</guid>
      <dc:creator>AKG1_old1</dc:creator>
      <dc:date>2017-04-18T11:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337366#M174902</link>
      <description>&lt;P&gt;did you tried to directly insert in your main search &lt;CODE&gt;earliest="03/01/1970:03:00:00" latest="03/01/1970:04:00:00"&lt;/CODE&gt;?&lt;BR /&gt;
in your example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mlc sourcetype=sun_jvm host=27-05-2016-05-27_18_24_42-archive service_name=mxmlc_2016-05-22_20-18-17.gc.log earliest="03/01/1970:03:00:00" latest="03/01/1970:04:00:00"
| table _time, earliest_time, latest_time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 12:44:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337366#M174902</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-04-18T12:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337367#M174903</link>
      <description>&lt;P&gt;@cusello . unfortunately, Its not working. I think we cannot specify earliest and latest time in search query. earliest and latest time shoud be outside the query.  but in my case its already set to earliest = 0 and latest =now and i can't chage it as it will inpact the output of search query.  &lt;/P&gt;

&lt;P&gt;I need condition in search query which consider only those records which fall in that time interval.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;      &amp;lt;query&amp;gt;Search query&amp;lt;/query&amp;gt;
      &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
      &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 13:11:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337367#M174903</guid>
      <dc:creator>AKG1_old1</dc:creator>
      <dc:date>2017-04-18T13:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337368#M174904</link>
      <description>&lt;P&gt;No you can use earliest and latest in a search ( see &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.3/SearchReference/SearchTimeModifiers"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.3/SearchReference/SearchTimeModifiers&lt;/A&gt; ).&lt;BR /&gt;
I used them in this format and run!&lt;BR /&gt;
you have to specify the full date and time in the correct format "mm/dd/yyyy:HH:MM:SS".&lt;BR /&gt;
Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 13:22:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337368#M174904</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-04-18T13:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337369#M174905</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mlc sourcetype=sun_jvm host=27-05-2016-05-27_18_24_42-archive service_name=mxmlc_2016-05-22_20-18-17.gc.log | eval _time = 0 + relative_time | eval earliest_time=strftime(180000,"%Y-%m-%d %H:%M:%S.%3q") | eval latest_time=strftime(183600,"%Y-%m-%d %H:%M:%S.%3q") | table _time, earliest_time, latest_time | where _time &amp;gt;= 180000 AND _time &amp;lt;= 183600
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or, better yet, just put it into the base search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mlc earliest=180000 latest=183600 sourcetype=sun_jvm host=27-05-2016-05-27_18_24_42-archive service_name=mxmlc_2016-05-22_20-18-17.gc.log | eval _time = 0 + relative_time | eval earliest_time=strftime(180000,"%Y-%m-%d %H:%M:%S.%3q") | eval latest_time=strftime(183600,"%Y-%m-%d %H:%M:%S.%3q") | table _time, earliest_time, latest_time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 13:58:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337369#M174905</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-18T13:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337370#M174906</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/1406"&gt;@woodcock&lt;/a&gt;. The first query should work fine for me but getting some unexpected results. when i am using both less than and greater than condition its not showing any results and when I am using only one condition its trim out the results but its not exactly matching with condition.&lt;/P&gt;

&lt;P&gt;Attached screenshot of both scenario.&lt;/P&gt;

&lt;P&gt;The second query won't work for me as I modifying  _time (eval _time = 0 + relative_time) and can't specify earliest and latest time before this.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/193268-single-condition.jpg" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/193270-search-both-condition.jpg" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:41:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337370#M174906</guid>
      <dc:creator>AKG1_old1</dc:creator>
      <dc:date>2020-09-29T13:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337371#M174907</link>
      <description>&lt;P&gt;Thanks @Anonymous. Its not working in my case but if  it works fine it won't solve my problem  as I am evaluating _time and can't specify earliest and latest before "eval _time = 0 + relative_time" and if i specify after this evaluation its technically incorrect.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:44:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337371#M174907</guid>
      <dc:creator>AKG1_old1</dc:creator>
      <dc:date>2020-09-29T13:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337372#M174908</link>
      <description>&lt;P&gt;You are not doing what I suggested.  It is not working because the you are comparing &lt;CODE&gt;_time&lt;/CODE&gt; to &lt;CODE&gt;latest_time&lt;/CODE&gt; and the former is an integer whereas the latter is a string.  If you must do it "like" that, use &lt;CODE&gt;fieldformat&lt;/CODE&gt; instead of &lt;CODE&gt;eval&lt;/CODE&gt;.  See my next answer for full example.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 15:54:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337372#M174908</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-18T15:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337373#M174909</link>
      <description>&lt;P&gt;Try using &lt;CODE&gt;fieldformat&lt;/CODE&gt; instead of &lt;CODE&gt;eval&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=mlc sourcetype=sun_jvm host=27-05-2016-05-27_18_24_42-archive service_name=mxmlc_2016-05-22_20-18-17.gc.log
| eval _time = 0 + relative_time
| eval earliest_time=180000
| fiedlformat earliest_time = strftime(earliest_time, "%Y-%m-%d %H:%M:%S.%3q")
| eval latest_time=183600
| fiedlformat latest_time = strftime(latest_time, "%Y-%m-%d %H:%M:%S.%3q")
| table _time, earliest_time, latest_time
| where _time &amp;gt;= earliest_time AND _time &amp;lt;= latest_time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 15:57:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337373#M174909</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-18T15:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can we fetch data for specific time interval by comparing time.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337374#M174910</link>
      <description>&lt;P&gt;It worked with minor modification. Thank you @woodcock &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 14:15:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-we-fetch-data-for-specific-time-interval-by-comparing/m-p/337374#M174910</guid>
      <dc:creator>AKG1_old1</dc:creator>
      <dc:date>2017-04-20T14:15:08Z</dc:date>
    </item>
  </channel>
</rss>

