<?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: Find earliest and latest event per day for a time range in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175541#M10868</link>
    <description>&lt;P&gt;Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="security" user="123456" EventCode=4624 OR EventCode=4634 earliest=-7d@d | stats earliest(_time) AS Earliest, latest(_time) AS Latest by date_mday | eval FirstEvent=strftime(Earliest,"%+") | eval LastEvent=strftime(Latest,"%+")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above should work for Windows security logs. Alternatively, this can be used too.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="security" user="123456" EventCode=4624 OR EventCode=4634 earliest=-7d@d | eval date_mday=strftime(_time,"%F") | stats earliest(_time) AS Earliest, latest(_time) AS Latest by date_mday | eval FirstEvent=strftime(Earliest,"%+") | eval LastEvent=strftime(Latest,"%+")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Aug 2014 00:54:33 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2014-08-08T00:54:33Z</dc:date>
    <item>
      <title>Find earliest and latest event per day for a time range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175540#M10867</link>
      <description>&lt;P&gt;I would like to find the first and last event per day over a given time range. So far I have figured out how to find just the first and last event for a given time range but if the time range is 5 days I'll get the earliest event for the first day and the last event on the last day. I'm just using the _time field to sort the date. I've tried the following.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="security" user="123456" EventCode=4624 OR EventCode=4634 earliest=-7d@d | stats earliest(_time) AS Earliest, latest(_time) AS Latest | eval FirstEvent=strftime(Earliest,"%+") | eval LastEvent=strftime(Latest,"%+")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This produces kind of what I want except over the 7 day time range.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FirstEvent                      LastEvent
Fri Aug 1 11:10:25 EST 2014     Fri Aug 8 05:57:06 EST 2014
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If someone could help me figure out how to do it day by day like below that would be excellent.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FirstEvent                      LastEvent
Fri Aug 1 11:10:25 EST 2014     Fri Aug 1 16:57:06 EST 2014
Fri Aug 2 11:10:25 EST 2014     Fri Aug 2 16:57:06 EST 2014
Fri Aug 3 11:10:25 EST 2014     Fri Aug 3 16:57:06 EST 2014
Fri Aug 4 11:10:25 EST 2014     Fri Aug 4 16:57:06 EST 2014
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And so on.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Aug 2014 23:23:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175540#M10867</guid>
      <dc:creator>conor_splunk</dc:creator>
      <dc:date>2014-08-07T23:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Find earliest and latest event per day for a time range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175541#M10868</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="security" user="123456" EventCode=4624 OR EventCode=4634 earliest=-7d@d | stats earliest(_time) AS Earliest, latest(_time) AS Latest by date_mday | eval FirstEvent=strftime(Earliest,"%+") | eval LastEvent=strftime(Latest,"%+")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above should work for Windows security logs. Alternatively, this can be used too.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="security" user="123456" EventCode=4624 OR EventCode=4634 earliest=-7d@d | eval date_mday=strftime(_time,"%F") | stats earliest(_time) AS Earliest, latest(_time) AS Latest by date_mday | eval FirstEvent=strftime(Earliest,"%+") | eval LastEvent=strftime(Latest,"%+")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Aug 2014 00:54:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175541#M10868</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-08-08T00:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find earliest and latest event per day for a time range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175542#M10869</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index="security" user="123456" EventCode=4624 OR EventCode=4634 earliest=-7d@d 
| bucket _time span=1d
| stats earliest(_time) as First latest(_time) as Last
  by _time
| eval First=strftimet(First,"%+") | eval Last=strftime(Last,"%+")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I prefer not to use &lt;CODE&gt;date_*&lt;/CODE&gt; fields (and instead use &lt;CODE&gt;_time&lt;/CODE&gt;) because those are not time-zone corrected, and they are not guaranteed to be on every event. (They will only be on events where a timestamp is extracted; ones that inherit a timestamp from a previous event or get a current timestamp won't have them.)&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Above is wrong. It needs to be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="security" user="123456" EventCode=4624 OR EventCode=4634 earliest=-7d@d 
| bucket _time span=1d as day
| stats earliest(_time) as First latest(_time) as Last
  by day
| eval First=strftimet(First,"%H:%M:%S") | eval Last=strftime(Last,"%H:%M:%S") | eval day=strftime(day,"%Y/%m/%d")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Aug 2014 01:05:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175542#M10869</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2014-08-08T01:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Find earliest and latest event per day for a time range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175543#M10870</link>
      <description>&lt;P&gt;That is true about date_* fields. Here, wouldn't all _time values will be transform into %Y/%m/%d 00:00 AM, and earliest and latest value of _time will be same.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Aug 2014 02:18:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175543#M10870</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-08-08T02:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Find earliest and latest event per day for a time range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175544#M10871</link>
      <description>&lt;P&gt;You are right, need to copy _time to a new field when bucketing it.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Aug 2014 05:02:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175544#M10871</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2014-08-08T05:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find earliest and latest event per day for a time range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175545#M10872</link>
      <description>&lt;P&gt;Neither of these quite worked for me but put me on the right track. I ended up doing what gkanapathy had without the bucket.&lt;/P&gt;

&lt;P&gt;index="security" user="123456" EventCode=4634 OR EventCode=4624)&lt;BR /&gt;
| eval Date=strftime(_time, "%d/%m/%Y")&lt;BR /&gt;
| stats earliest(_time) AS Earliest, latest(_time) AS Latest by Date&lt;BR /&gt;
| eval Logon=strftime(Earliest,"%+")&lt;BR /&gt;
| eval Logoff=strftime(Latest,"%+")&lt;BR /&gt;
| table Date, Logon, Logoff&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:17:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Find-earliest-and-latest-event-per-day-for-a-time-range/m-p/175545#M10872</guid>
      <dc:creator>conor_splunk</dc:creator>
      <dc:date>2020-09-28T17:17:37Z</dc:date>
    </item>
  </channel>
</rss>

