<?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: Finding the Duration between two timestamps in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499387#M139088</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;| eval Time = strptime(timestamp, "%Y-%m-%d %H:%M:%S")
| stats earliest(Time) as BeginTime, latest(Time) as FinishTime by NameOfJob
| eval dur=FinishTime-BeginTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Oct 2019 19:57:25 GMT</pubDate>
    <dc:creator>sandeepmakkena</dc:creator>
    <dc:date>2019-10-09T19:57:25Z</dc:date>
    <item>
      <title>Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499384#M139085</link>
      <description>&lt;P&gt;I am currently attempting to create a query that returns the Name of the job, Begin Time, Finish Time, and Duration. &lt;/P&gt;

&lt;P&gt;Here is my attempt: &lt;/P&gt;

&lt;P&gt;NameOfJob = EXAMPLE | spath timestamp | search timestamp=*&lt;BR /&gt;
| stats earliest(timestamp) as BeginTime, latest(timestamp) as FinishTime&lt;BR /&gt;
by NameOfJob&lt;BR /&gt;
| eval BeginTime=substr(BeginTime,1,13)&lt;BR /&gt;
| eval BeginTimeD=strftime(BeginTime/1000, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval FinishTime=substr(FinishTime,1,13)&lt;BR /&gt;
| eval FinishTimeD=strftime(FinishTime/1000, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval seconds=FinishTimeD-BeginTimeD | eval seconds=seconds/1000 | eval minutes=seconds/60 | eval hours=minutes/60 | table NameOfJob BeginTime FinishTime minutes | sort column FinishTime&lt;/P&gt;

&lt;P&gt;However, the "minutes" a.k.a &lt;STRONG&gt;duration&lt;/STRONG&gt; is returning empty. Does this have something to do with the format of timestamp?&lt;BR /&gt;
Here is an example of the timestamp format I am dealing with:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;timestamp: 2019-07-28T04:01:22:041Z&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;I need this duration column to return the time between BeginTime and FinishTime. Any help is appreciated. Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 20:42:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499384#M139085</guid>
      <dc:creator>tyhopping1</dc:creator>
      <dc:date>2019-10-08T20:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499385#M139086</link>
      <description>&lt;P&gt;| eval BeginTime = strptime(BeginTime, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval FinishTime = strptime(FinishTime, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval dur=FinishTime-BeginTime&lt;/P&gt;

&lt;P&gt;This is working fine, can you share some sample data. I not sure why you're doing this &lt;CODE&gt;| eval BeginTime=substr(BeginTime,1,13)&lt;/CODE&gt;. sample data would make more sense. &lt;/P&gt;</description>
      <pubDate>Tue, 08 Oct 2019 21:17:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499385#M139086</guid>
      <dc:creator>sandeepmakkena</dc:creator>
      <dc:date>2019-10-08T21:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499386#M139087</link>
      <description>&lt;P&gt;I am limited to what I can share. Here is a sample event:&lt;BR /&gt;
 counters: { [-]&lt;BR /&gt;
     CountOfRecords: 4&lt;BR /&gt;
   }&lt;BR /&gt;
   extract: FAAFS&lt;BR /&gt;
   NameOfJob: EXAMPLE&lt;BR /&gt;
   level: Information&lt;BR /&gt;
   message: POPULATED&lt;BR /&gt;
   microService: { [+]&lt;BR /&gt;
   }&lt;BR /&gt;
   OutputName: FAAFD&lt;BR /&gt;
   DateOfProcess: 2019123&lt;BR /&gt;
   timestamp: 2019-07-28T04:01:22.041Z&lt;/P&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 19:45:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499386#M139087</guid>
      <dc:creator>tyhopping1</dc:creator>
      <dc:date>2019-10-09T19:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499387#M139088</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| eval Time = strptime(timestamp, "%Y-%m-%d %H:%M:%S")
| stats earliest(Time) as BeginTime, latest(Time) as FinishTime by NameOfJob
| eval dur=FinishTime-BeginTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 19:57:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499387#M139088</guid>
      <dc:creator>sandeepmakkena</dc:creator>
      <dc:date>2019-10-09T19:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499388#M139089</link>
      <description>&lt;P&gt;It's okay, Just wanted to time format. Can you try below one and let me know if you have any questions.&lt;BR /&gt;&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 20:00:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499388#M139089</guid>
      <dc:creator>sandeepmakkena</dc:creator>
      <dc:date>2019-10-09T20:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499389#M139090</link>
      <description>&lt;P&gt;Unfortunately, I get null results from this query. &lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 15:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499389#M139090</guid>
      <dc:creator>tyhopping1</dc:creator>
      <dc:date>2019-10-10T15:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499390#M139091</link>
      <description>&lt;P&gt;Easiest way is to use strptime to format your time into epoch and then do the math to convert to minutes/hours/days whatever. Here is a run anywhere example using your date format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval beginTime="2019-07-28T04:01:22.041Z"
| eval endTime="2019-07-28T05:01:22.041Z"
| eval beginTimeEpoch=strptime(beginTime, "%Y-%m-%dT%H:%M:%S")
| eval endTimeEpoch=strptime(endTime, "%Y-%m-%dT%H:%M:%S")
| eval durationInMinutes=(endTimeEpoch-beginTimeEpoch)/60
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you have multiple events then you'll need to do a stats with min/max on the epochs before you calculate the duration, something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats min(beginTimeEpoch) as beginTimeEpoch, max(endTimeEpoch) as endTimeEpoch by yourField
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Enjoy!!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 16:28:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499390#M139091</guid>
      <dc:creator>tjago11</dc:creator>
      <dc:date>2019-10-10T16:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499391#M139092</link>
      <description>&lt;P&gt;Is your timestamp field is extracted?&lt;BR /&gt;
Or As for your data in JSON format, you might also want to use &lt;CODE&gt;| spath&lt;/CODE&gt; on that field.&lt;BR /&gt;
I did a test on my data it works find. &lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 19:36:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499391#M139092</guid>
      <dc:creator>sandeepmakkena</dc:creator>
      <dc:date>2019-10-11T19:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Duration between two timestamps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499392#M139093</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YouShouldAlwaysSpecifyAnIndex AND sourcetype=AndSourcetypeToo AND NameOfJob=EXAMPLE
| spath timestamp
| eval timestamp=tonumber(substr(timestamp,1,13))/1000
| stats min(timestamp) AS BeginTime, max(timestamp) AS FinishTime BY NameOfJob
| fieldformat BeginTime=strftime(BeginTime, "%Y-%m-%d %H:%M:%S")
| fieldformat FinishTime=strftime(FinishTime, "%Y-%m-%d %H:%M:%S")
| eval minutes=(FinishTime-BeginTime)/60
| sort 0 FinishTime
| table NameOfJob BeginTime FinishTime minutes
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Oct 2019 21:24:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-the-Duration-between-two-timestamps/m-p/499392#M139093</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-12T21:24:03Z</dc:date>
    </item>
  </channel>
</rss>

