<?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: Using relative time with where command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-relative-time-with-where-command/m-p/328944#M162593</link>
    <description>&lt;P&gt;Hi @orion44,&lt;/P&gt;

&lt;P&gt;Have you try to compare it with epochtime?&lt;BR /&gt;
Can you please try this? I have keep same logic just change in time format.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval mytime=_time
 | stats count(SRC) as "Source IP" by SRC mytime 
 | dedup SRC sortby mytime 
 | rename SRC as "Source IP" | eval T1=strptime("2018-03-01","%Y-%m-%d"),T2=strptime("2018-03-02","%Y-%m-%d")
 | where mytime &amp;gt; T1 AND mytime &amp;lt; T2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sun, 04 Mar 2018 13:34:45 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2018-03-04T13:34:45Z</dc:date>
    <item>
      <title>Using relative time with where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-relative-time-with-where-command/m-p/328943#M162592</link>
      <description>&lt;P&gt;I'm able to find all the previous day's events by hard coding in date ranges as such:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;where mytime &amp;gt; "2018-03-01" AND mytime &amp;lt; "2018-03-02"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I use the where command to search for the relative time of yesterday?&lt;/P&gt;

&lt;P&gt;Here's the snippet from my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval mytime=strftime(_time,"%Y-%m-%dT%H:%M:%S%z") 
| stats count(SRC) as "Source IP" by SRC mytime 
| dedup SRC sortby mytime 
| rename SRC as "Source IP" 
| where mytime &amp;gt; "2018-03-01" AND mytime &amp;lt; "2018-03-02"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Mar 2018 11:17:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-relative-time-with-where-command/m-p/328943#M162592</guid>
      <dc:creator>orion44</dc:creator>
      <dc:date>2018-03-04T11:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using relative time with where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-relative-time-with-where-command/m-p/328944#M162593</link>
      <description>&lt;P&gt;Hi @orion44,&lt;/P&gt;

&lt;P&gt;Have you try to compare it with epochtime?&lt;BR /&gt;
Can you please try this? I have keep same logic just change in time format.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval mytime=_time
 | stats count(SRC) as "Source IP" by SRC mytime 
 | dedup SRC sortby mytime 
 | rename SRC as "Source IP" | eval T1=strptime("2018-03-01","%Y-%m-%d"),T2=strptime("2018-03-02","%Y-%m-%d")
 | where mytime &amp;gt; T1 AND mytime &amp;lt; T2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 04 Mar 2018 13:34:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-relative-time-with-where-command/m-p/328944#M162593</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-03-04T13:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using relative time with where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-relative-time-with-where-command/m-p/328945#M162594</link>
      <description>&lt;P&gt;Instead of converting times to human-readable formats before comparing them, the most straightforward way to write your search to always look for values from "yesterday" (regardless of what today is) would be to use the &lt;CODE&gt;relative_time&lt;/CODE&gt; function, as you alluded to. Integrating this directly into your current search structure would look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count(SRC) as "Source IP" by SRC _time 
| dedup SRC sortby _time 
| rename SRC as "Source IP" 
| where _time&amp;gt;=relative_time(now(), "-1d@d") AND _time&amp;lt;=relative_time(now(), "@d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will allow Splunk to do all comparisons using epoch time strings and still display the time value in human-readable format, something Splunk will do by default with only the &lt;CODE&gt;_time&lt;/CODE&gt; field.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Mar 2018 16:13:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-relative-time-with-where-command/m-p/328945#M162594</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-03-04T16:13:37Z</dc:date>
    </item>
  </channel>
</rss>

