<?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 subtract dates from two events to find the duration? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273755#M82576</link>
    <description>&lt;P&gt;Try this *&lt;STRONG&gt;&lt;EM&gt;UPDATED&lt;/EM&gt;&lt;/STRONG&gt;*&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; base search | stats latest(eval(if(Ticket_Status="RESOLVED"), End_Time, null())) as resolved latest(eval(if(Ticket_Status="INPROG"), End_Time, null())) as inprog by Ticket_Number | eval resolved=strptime(resolved, "%m/%d/%Y %H:%M:%S %p") | eval inprog=strptime(inprog, "%m/%d/%Y %H:%M:%S %p") | eval duration=resolved-inprog | eval duration=tostring(duration, "duration") | convert ctime(resolved) ctime(inprog) timeformat="%m/%d/%Y %H:%M:%S %p" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 26 Oct 2016 18:07:01 GMT</pubDate>
    <dc:creator>sundareshr</dc:creator>
    <dc:date>2016-10-26T18:07:01Z</dc:date>
    <item>
      <title>How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273754#M82575</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;

&lt;P&gt;I have two events which I have uploaded in CSV format and the events will be consistent as below:  &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Ticket_Number,Created_Date,Ticket_Status,End_Time&lt;/STRONG&gt;&lt;BR /&gt;
INABCDEF,07/14/2016 06:36:47 AM,INPROG,07/14/2016 06:47:14 AM&lt;BR /&gt;
INABCDEF,07/14/2016 06:36:47 AM,RESOLVED,07/14/2016 08:58:25 AM&lt;/P&gt;

&lt;P&gt;I was able to find that the duration for the ticket INABCDEF was in INPROG by subtracting End_Time and Created_Date by using eval with strptime.&lt;/P&gt;

&lt;P&gt;To find the duration for the ticket with the status RESOLVE, I will need to subtract the End_Time when the Ticket status was RESOLVED from the End_Time when the ticket was INPROG.&lt;BR /&gt;
i.e Subtract the End_Time of event 2 where status is RESOLVED from the End_Time of event1 where status is INPROG.    &lt;/P&gt;

&lt;P&gt;I am new to Splunk and I don't know how to subtract field values from two different events. Let me know if anyone knows the answer to this. &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:33:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273754#M82575</guid>
      <dc:creator>aamirs291</dc:creator>
      <dc:date>2020-09-29T11:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273755#M82576</link>
      <description>&lt;P&gt;Try this *&lt;STRONG&gt;&lt;EM&gt;UPDATED&lt;/EM&gt;&lt;/STRONG&gt;*&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; base search | stats latest(eval(if(Ticket_Status="RESOLVED"), End_Time, null())) as resolved latest(eval(if(Ticket_Status="INPROG"), End_Time, null())) as inprog by Ticket_Number | eval resolved=strptime(resolved, "%m/%d/%Y %H:%M:%S %p") | eval inprog=strptime(inprog, "%m/%d/%Y %H:%M:%S %p") | eval duration=resolved-inprog | eval duration=tostring(duration, "duration") | convert ctime(resolved) ctime(inprog) timeformat="%m/%d/%Y %H:%M:%S %p" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2016 18:07:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273755#M82576</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-10-26T18:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273756#M82577</link>
      <description>&lt;P&gt;Hi Sundareshr,&lt;/P&gt;

&lt;P&gt;When I ran the above code from |stats latest ... I am receiving the following error&lt;BR /&gt;
Error in 'SearchProcessor': Mismatched quotes and/or parenthesis.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 18:19:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273756#M82577</guid>
      <dc:creator>aamirs291</dc:creator>
      <dc:date>2016-10-26T18:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273757#M82578</link>
      <description>&lt;P&gt;I would also like to add to this that I would not want to use the value for &lt;STRONG&gt;_time&lt;/STRONG&gt; but instead as mentioned in the question I want ; &lt;BR /&gt;
RESOLUTION TIME = End_Time when the ticket is RESOLVED minus End_Time when the ticket is INPROG. I want the values from the table I mentioned instead of the &lt;STRONG&gt;_time&lt;/STRONG&gt; which splunk generates automatically. In Summary, Subtracting two user defined dates from two events. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:33:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273757#M82578</guid>
      <dc:creator>aamirs291</dc:creator>
      <dc:date>2020-09-29T11:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273758#M82579</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search giving fields Ticket_Number,Created_Date,Ticket_Status,End_Time
| convert mktime(Created_Date) mktime(End_Time) timeformat="%m/%d/%Y %H:%M:%S %p"
| eval InProgressTime=if(Ticket_Status="INPROG",End_Time,null())
| eval ResolvedTime=if(Ticket_Status="RESOLVED",End_Time,null())
| stats values(Created_Date) as Created_Date values(InProgressTime) as InProgressTime values(ResolvedTime) as ResolvedTime by Ticket_Number
| eval Duration_INPROG=InProgressTime-Created_Date | eval Duration_RESOLVED=ResolvedTime-Created_Date
| convert ctime(Created_Date) ctime(*Time) timeformat="%m/%d/%Y %H:%M:%S %p"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2016 18:48:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273758#M82579</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-26T18:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273759#M82580</link>
      <description>&lt;P&gt;Try the updated answer&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2016 19:00:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273759#M82580</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-10-26T19:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273760#M82581</link>
      <description>&lt;P&gt;I am getting the following error when I run the updated code &lt;BR /&gt;
Error in 'stats' command: The eval expression for dynamic field 'eval(if(Ticket_Status="RESOLVED"), End_Time, null())' is invalid. Error='The operator at ', End_Time, null()' is invalid.'&lt;/P&gt;

&lt;P&gt;Note: somesoni2's code worked with some tweaks. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:33:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273760#M82581</guid>
      <dc:creator>aamirs291</dc:creator>
      <dc:date>2020-09-29T11:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to subtract dates from two events to find the duration?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273761#M82582</link>
      <description>&lt;P&gt;Somesoni2,&lt;/P&gt;

&lt;P&gt;Duration_RESOLVED is supposed to be ResolvedTime-InProgressTime as I had mentioned in my question. I did this and got the value I required. Thank you for the code.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2016 09:20:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subtract-dates-from-two-events-to-find-the-duration/m-p/273761#M82582</guid>
      <dc:creator>aamirs291</dc:creator>
      <dc:date>2016-10-27T09:20:36Z</dc:date>
    </item>
  </channel>
</rss>

