<?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 edit my stats search to only display results older than X days? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238306#M70797</link>
    <description>&lt;P&gt;Try like this (checking last logged in time is 2 day older than current time. Adjust where clause per your need)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=o365 Operation=UserLoggedIn |
stats max(_time) as mytime by UserId
| where mytime&amp;gt;(relative_time(now(),"-2d")
| eval mytime=strftime(mytime, "%m/%d/%Y") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to keep 1 day granularity, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=o365 Operation=UserLoggedIn |
stats max(_time) as mytime by UserId
| where relative_time(mytime,"@d") &amp;gt;=(relative_time(now(),"-2d@d"")
| eval mytime=strftime(mytime, "%m/%d/%Y") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 13 Jan 2017 17:17:15 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-01-13T17:17:15Z</dc:date>
    <item>
      <title>How to edit my stats search to only display results older than X days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238305#M70796</link>
      <description>&lt;P&gt;I am running this stats latest search for Microsoft Cloud Services UserLoggedIn: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=o365 Operation=UserLoggedIn |
eval mytime=strftime(_time, "%m/%d/%Y") |
stats latest(mytime) As mytime by UserId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After it pulls the latest event, I need to search through and only pull out events that are older than X days.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2017 15:03:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238305#M70796</guid>
      <dc:creator>wilcoxj</dc:creator>
      <dc:date>2017-01-13T15:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my stats search to only display results older than X days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238306#M70797</link>
      <description>&lt;P&gt;Try like this (checking last logged in time is 2 day older than current time. Adjust where clause per your need)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=o365 Operation=UserLoggedIn |
stats max(_time) as mytime by UserId
| where mytime&amp;gt;(relative_time(now(),"-2d")
| eval mytime=strftime(mytime, "%m/%d/%Y") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to keep 1 day granularity, try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=o365 Operation=UserLoggedIn |
stats max(_time) as mytime by UserId
| where relative_time(mytime,"@d") &amp;gt;=(relative_time(now(),"-2d@d"")
| eval mytime=strftime(mytime, "%m/%d/%Y") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Jan 2017 17:17:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238306#M70797</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-01-13T17:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my stats search to only display results older than X days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238307#M70798</link>
      <description>&lt;P&gt;somesoni2 - good answer but switch your tests - "logged in time older than 2 days ago" means "date less than 2 days ago".&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2017 23:39:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238307#M70798</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-13T23:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my stats search to only display results older than X days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238308#M70799</link>
      <description>&lt;P&gt;In your original code, you are reformatting the _time of every record, rather than only reformatting the time of the latest value.  Keep the _time in epoch format until after the aggregation.  somesoni2 fixed that in his code, but didn't call it to your attention.&lt;/P&gt;

&lt;P&gt;Here are some search efficiency notes for splunk - &lt;BR /&gt;
1) Eliminate fields (or entire records) at the earliest possible moment&lt;BR /&gt;
2) Do your calculations at the last possible moment. &lt;/P&gt;

&lt;P&gt;The resulting code looks something like this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=o365 Operation=UserLoggedIn 
| fields _time UserId
| stats latest(_time) As mytime by UserId
| where mytime &amp;lt;= (relative_time(now(),"-2d"))
| eval mytime=strftime(_time, "%m/%d/%Y") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Jan 2017 23:43:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-stats-search-to-only-display-results-older-than-X/m-p/238308#M70799</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-13T23:43:49Z</dc:date>
    </item>
  </channel>
</rss>

