<?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 write a search using eval to create a new field with values calculated from the difference between two time fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201701#M58436</link>
    <description>&lt;P&gt;Is diff results are in seconds ? need to do (diff/3600)?&lt;/P&gt;</description>
    <pubDate>Mon, 01 Aug 2016 18:39:44 GMT</pubDate>
    <dc:creator>splunker9999</dc:creator>
    <dc:date>2016-08-01T18:39:44Z</dc:date>
    <item>
      <title>How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201699#M58434</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;We integrated Splunk to ServiceNow and looking to find a late closure incidents.&lt;/P&gt;

&lt;P&gt;For this we have 2 fields &lt;STRONG&gt;Stopdate&lt;/STRONG&gt;, &lt;STRONG&gt;closeddate&lt;/STRONG&gt;... we need to evaluate a new field &lt;STRONG&gt;Late Closure&lt;/STRONG&gt; using these 2 dates.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;we need to find the diff of Stopdate and closeddate&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;We need to list if Late closure &amp;gt; 5 (excluding weekends)&lt;/LI&gt;
&lt;LI&gt;For few of them, we don't have closed date. We need to compare with current date and evaluate number of late closure for these?&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Stopdate and closeddate is of this format: &lt;CODE&gt;08-01-2016 05:00:00 MST&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search...|table Stopdate closeddate
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can someone please help us with the search?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 18:09:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201699#M58434</guid>
      <dc:creator>splunker9999</dc:creator>
      <dc:date>2016-08-01T18:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201700#M58435</link>
      <description>&lt;P&gt;Comparing dates requires converting them to epoch (integer) form.  Do that with &lt;CODE&gt;strptime(field, "%m-%d-%Y %H:%M:%S %Z")&lt;/CODE&gt;.&lt;BR /&gt;
Allowing for a missing closed date is easy with &lt;CODE&gt;isnull&lt;/CODE&gt;. &lt;BR /&gt;
I'm at a loss for a way to exclude weekends, but better heads than mine may have ideas.&lt;/P&gt;

&lt;P&gt;A sample query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index= foo | eval stopTS = strptime(Stopdate, "%m-%d-%Y %H:%M:%S %Z") | eval closedTS=if(isnull(closedDate),now(), strptime(closedDate, "%m-%d-%Y %H:%M:%S %Z")) | eval diff = (closedTS - stopTS)/86400 | where diff &amp;gt; 5 | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Aug 2016 18:34:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201700#M58435</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-08-01T18:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201701#M58436</link>
      <description>&lt;P&gt;Is diff results are in seconds ? need to do (diff/3600)?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 18:39:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201701#M58436</guid>
      <dc:creator>splunker9999</dc:creator>
      <dc:date>2016-08-01T18:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201702#M58437</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;P&gt;*&lt;STRONG&gt;&lt;EM&gt;UPDATED&lt;/EM&gt;&lt;/STRONG&gt;* &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | eval closedate=coalesce(strptime(closedate, "%m-%d-%Y %H:%M:%S") , now()) | stats latest(stopdate) as stopdate latest(closedate) as closedate by ticketid | eval stopdate=strptime(stopdate, "%m-%d-%Y %H:%M:%S") | eval lateclosure=closedate-stopdate | where lateclosure&amp;gt;=5*86400 | eval busdays=mvrange(stopdate, closedate, "1d") | eval busdays=strftime(busdays, "%a") | eval busdays=mvfilter(busdays!="Sat" AND busdays!="Sun") | where mvcount(busdays)&amp;gt;=5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Aug 2016 18:41:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201702#M58437</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-01T18:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201703#M58438</link>
      <description>&lt;P&gt;| eval busdays=mvrange(stopdate, closeddate, 1d) - I am getting malfunction error in eval here?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 18:52:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201703#M58438</guid>
      <dc:creator>splunker9999</dc:creator>
      <dc:date>2016-08-01T18:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201704#M58439</link>
      <description>&lt;P&gt;Yes, diff is in seconds.  Good catch.  I'll update the answer.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 19:56:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201704#M58439</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-08-01T19:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201705#M58440</link>
      <description>&lt;P&gt;I considered using coalesce, but was concerned about what strptime would return if closedate doesn't exist.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 19:58:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201705#M58440</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-08-01T19:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search using eval to create a new field with values calculated from the difference between two time fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201706#M58441</link>
      <description>&lt;P&gt;@splunker9999 try the updated version. 1d should have been in quotes. Also removed the &lt;CODE&gt;mvexpand&lt;/CODE&gt; command.&lt;/P&gt;

&lt;P&gt;@richgalloway, if &lt;CODE&gt;closedate&lt;/CODE&gt; doesn't exists, &lt;CODE&gt;closedate&lt;/CODE&gt; will be populated with &lt;CODE&gt;now()&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 20:31:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-using-eval-to-create-a-new-field-with/m-p/201706#M58441</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-01T20:31:52Z</dc:date>
    </item>
  </channel>
</rss>

