<?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 set earliest time based on current time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462634#M130425</link>
    <description>&lt;P&gt;I thought about it a little more and something like this should work. It is certainly not perfect though - you would want to check month and year crossovers also to guarantee accuracy. Change log_level to &lt;CODE&gt;WARN&lt;/CODE&gt; or &lt;CODE&gt;INFO&lt;/CODE&gt; if you're environment is perfect and doesn't have errors.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal log_level=ERROR
| eval curr_date_hour = strftime(now(), "%H"),
       curr_date_mday = strftime(now(), "%d")
| eval search_mday    = case(curr_date_hour &amp;lt;= 6, curr_date_mday - 1,
                             curr_date_hour &amp;gt;  6, curr_date_mday)
| eval search_hour    = case(curr_date_hour &amp;lt;  6, 22,
                             curr_date_hour &amp;gt;  22, 22,
                             curr_date_hour &amp;gt;  19, 19,
                             curr_date_hour &amp;gt;  14, 14,
                             curr_date_hour &amp;gt;   6,  6)
| where (search_hour != 22 AND search_mday     = date_mday AND date_hour &amp;gt;= search_hour) OR
        (search_hour  = 22 AND search_mday     = date_mday AND date_hour &amp;gt;= search_hour) OR
        (search_hour  = 22 AND search_mday + 1 = date_mday)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Aug 2019 18:14:09 GMT</pubDate>
    <dc:creator>jacobpevans</dc:creator>
    <dc:date>2019-08-27T18:14:09Z</dc:date>
    <item>
      <title>How to set earliest time based on current time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462631#M130422</link>
      <description>&lt;P&gt;I am ingesting data at 6AM, 2PM, 7PM, 10PM (CST)&lt;BR /&gt;
Is there anyway I could have my query check the time and set earliest to the time that it past last?&lt;/P&gt;

&lt;P&gt;ie: &lt;BR /&gt;
It is 8AM CST time, the search would set earliest to 6AM&lt;BR /&gt;
It is 9PM CST time, the search would set earliest to 7PM&lt;/P&gt;

&lt;P&gt;Thanks &lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 16:20:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462631#M130422</guid>
      <dc:creator>JoshuaJohn</dc:creator>
      <dc:date>2019-08-27T16:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to set earliest time based on current time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462632#M130423</link>
      <description>&lt;P&gt;I'm sure it's possible, but the easier way to do it would be to:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Change the ingestion to run once every 6 hours (still 4 times per day), and set your search to &lt;CODE&gt;earliest=-6h&lt;/CODE&gt;, or&lt;/LI&gt;
&lt;LI&gt;Set the search to last 24 hours (or something greater than 8 hours), and perform a &lt;CODE&gt;dedup&lt;/CODE&gt; to ensure your results only contain the latest data.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 27 Aug 2019 17:16:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462632#M130423</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-08-27T17:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to set earliest time based on current time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462633#M130424</link>
      <description>&lt;P&gt;try &lt;CODE&gt;earliest=-2h&lt;/CODE&gt;  in your search query?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 17:25:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462633#M130424</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-08-27T17:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to set earliest time based on current time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462634#M130425</link>
      <description>&lt;P&gt;I thought about it a little more and something like this should work. It is certainly not perfect though - you would want to check month and year crossovers also to guarantee accuracy. Change log_level to &lt;CODE&gt;WARN&lt;/CODE&gt; or &lt;CODE&gt;INFO&lt;/CODE&gt; if you're environment is perfect and doesn't have errors.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal log_level=ERROR
| eval curr_date_hour = strftime(now(), "%H"),
       curr_date_mday = strftime(now(), "%d")
| eval search_mday    = case(curr_date_hour &amp;lt;= 6, curr_date_mday - 1,
                             curr_date_hour &amp;gt;  6, curr_date_mday)
| eval search_hour    = case(curr_date_hour &amp;lt;  6, 22,
                             curr_date_hour &amp;gt;  22, 22,
                             curr_date_hour &amp;gt;  19, 19,
                             curr_date_hour &amp;gt;  14, 14,
                             curr_date_hour &amp;gt;   6,  6)
| where (search_hour != 22 AND search_mday     = date_mday AND date_hour &amp;gt;= search_hour) OR
        (search_hour  = 22 AND search_mday     = date_mday AND date_hour &amp;gt;= search_hour) OR
        (search_hour  = 22 AND search_mday + 1 = date_mday)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Aug 2019 18:14:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-earliest-time-based-on-current-time/m-p/462634#M130425</guid>
      <dc:creator>jacobpevans</dc:creator>
      <dc:date>2019-08-27T18:14:09Z</dc:date>
    </item>
  </channel>
</rss>

