<?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 the number of days between the earliest and latest event. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Find-the-number-of-days-between-the-earliest-and-latest-event/m-p/669712#M229638</link>
    <description>&lt;P&gt;It would help to know what you've tried already so we don't suggest something that doesn't work.&lt;/P&gt;&lt;P&gt;A thing to remember is Splunk can't compare timestamps in text form - they must be converted to epoch (integer) form, first.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="Employee, Time, Country
John Doe, 2023-11-15T20:05:31.000+00:00, France
John Doe, 2023-11-18T10:00:31.000+00:00, France
John Doe, 2023-11-20T10:05:31.000+00:00, United States
John Doe, 2023-11-25T20:05:31.000+00:00, United States"
``` Above creates demo data.  Delete IRL ```
``` Convert Time to epoch ```
| eval eTime=strptime(Time, "%Y-%m-%dT%H:%M:%S.%3N%:z")
``` Find the lowest and highest time for each employee/country pair ```
| stats min(eTime) as start, max(eTime) as end by Employee,Country
``` Calculate the duration in days.  Add "d" suffix for display ```
| eval duration=round((end-start)/86400,0) . "d"
| table Employee duration Country&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 25 Nov 2023 20:58:45 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2023-11-25T20:58:45Z</dc:date>
    <item>
      <title>Find the number of days between the earliest and latest event.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-the-number-of-days-between-the-earliest-and-latest-event/m-p/669710#M229637</link>
      <description>&lt;P&gt;I need help with an employee travel analysis report.&lt;BR /&gt;I have an index containing information about employee office check-ins in various countries. Events have fields Employee, Time, Country&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;John Doe,&amp;nbsp;&lt;SPAN&gt;2023-11-15T20:05:31.000+00:00,&amp;nbsp;&lt;/SPAN&gt;France&lt;BR /&gt;...&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="andale mono,times"&gt;John Doe,&amp;nbsp;&lt;SPAN&gt;2023-11-18T10:00:31.000+00:00,&amp;nbsp;&lt;/SPAN&gt;France&lt;BR /&gt;...&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;John Doe,&amp;nbsp;&lt;SPAN&gt;2023-11-20T10:05:31.000+00:00&lt;/SPAN&gt;, United States&lt;BR /&gt;...&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;John Doe,&amp;nbsp;&lt;SPAN&gt;2023-11-25T20:05:31.000+00:00&lt;/SPAN&gt;, United States&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end I would like to get the result showing duration in days between first checkin and last checkin per employee per country&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;John Doe, 3d, France&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;John Doe, 5d, United States&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2023 20:24:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-the-number-of-days-between-the-earliest-and-latest-event/m-p/669710#M229637</guid>
      <dc:creator>kimberlytrayson</dc:creator>
      <dc:date>2023-11-25T20:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find the number of days between the earliest and latest event.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-the-number-of-days-between-the-earliest-and-latest-event/m-p/669712#M229638</link>
      <description>&lt;P&gt;It would help to know what you've tried already so we don't suggest something that doesn't work.&lt;/P&gt;&lt;P&gt;A thing to remember is Splunk can't compare timestamps in text form - they must be converted to epoch (integer) form, first.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="Employee, Time, Country
John Doe, 2023-11-15T20:05:31.000+00:00, France
John Doe, 2023-11-18T10:00:31.000+00:00, France
John Doe, 2023-11-20T10:05:31.000+00:00, United States
John Doe, 2023-11-25T20:05:31.000+00:00, United States"
``` Above creates demo data.  Delete IRL ```
``` Convert Time to epoch ```
| eval eTime=strptime(Time, "%Y-%m-%dT%H:%M:%S.%3N%:z")
``` Find the lowest and highest time for each employee/country pair ```
| stats min(eTime) as start, max(eTime) as end by Employee,Country
``` Calculate the duration in days.  Add "d" suffix for display ```
| eval duration=round((end-start)/86400,0) . "d"
| table Employee duration Country&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 25 Nov 2023 20:58:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-the-number-of-days-between-the-earliest-and-latest-event/m-p/669712#M229638</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-11-25T20:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Find the number of days between the earliest and latest event.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-the-number-of-days-between-the-earliest-and-latest-event/m-p/669714#M229639</link>
      <description>&lt;P&gt;I often simplify time deltas using stats range():&lt;/P&gt;&lt;P&gt;| stats range(eval(strptime(Time, "%Y-%m-%dT%H:%M:%S.%3N%:z"))) as duration by Employee Country&lt;BR /&gt;| fieldformat duration=round(duration/86400, 0)."d"&lt;BR /&gt;``` or ```&lt;BR /&gt;``` | fieldformat duration=tostring(duration, "duration") ```&lt;BR /&gt;``` for Splunk-normalized [D+]HH:MM:SS display ```&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2023 21:25:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-the-number-of-days-between-the-earliest-and-latest-event/m-p/669714#M229639</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2023-11-25T21:25:22Z</dc:date>
    </item>
  </channel>
</rss>

