<?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 do I subtract two fields containing %m%d%y format time values to get the age of an event? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352521#M104346</link>
    <description>&lt;P&gt;@493669 can you explain what's happening in the evals so I can better grasp it?&lt;/P&gt;

&lt;P&gt;I also would like to compute the duration between another to fields, e.g.  CreationDate - ClosureDate.  Then I would like get the average duration in days for both  "open events" and events that have been closed.  &lt;/P&gt;

&lt;P&gt;Open events would be any events that are not marked as Closed=1&lt;BR /&gt;
Closed event would be any events that are marked as Closed=0&lt;/P&gt;</description>
    <pubDate>Thu, 08 Mar 2018 02:19:06 GMT</pubDate>
    <dc:creator>johnward4</dc:creator>
    <dc:date>2018-03-08T02:19:06Z</dc:date>
    <item>
      <title>How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352518#M104343</link>
      <description>&lt;P&gt;I'm trying to create a new field that is the result of the Current Date minus the time stamp when my events were created.  My overall goal is the show  duration=the # of days between my current date and when the events were created. &lt;/P&gt;

&lt;P&gt;Current query : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| index=test sourcetype=testsourcetype username, Subject
| eval currentdate= now() 
| convert timeformat="%d %m %Y %H:%M:%S %Z" ctime(currentdate) AS c_time 
| eval Event=strftime (_time, "%d %m %Y %H:%M:%S %Z")
| eval duration=('c_time'-'Event')/(60*60)
| table username, Subject, ID, _time, c_time, Event, duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:11:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352518#M104343</guid>
      <dc:creator>johnward4</dc:creator>
      <dc:date>2018-02-01T06:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352519#M104344</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test sourcetype=testsourcetype
 | eval currentdate= now() 
 | convert timeformat="%d %m %Y %H:%M:%S %Z" ctime(currentdate) AS c_time 
 | eval Event=strftime (_time, "%d %m %Y %H:%M:%S %Z"),c_time1=c_time
 |eval c_time1=strptime(c_time1,"%d %m %Y %H:%M:%S %Z") ,Event1=strptime(Event,"%d %m %Y %H:%M:%S %Z")
 | eval duration=('c_time1'-'_time')/(24*60*60)
 | table username, Subject, ID, _time, c_time, Event1, duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:30:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352519#M104344</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-02-01T06:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352520#M104345</link>
      <description>&lt;P&gt;You can directly find the difference between &lt;STRONG&gt;now()&lt;/STRONG&gt; and &lt;STRONG&gt;_time&lt;/STRONG&gt; and divide it by &lt;STRONG&gt;86400&lt;/STRONG&gt; to get duration in number of days, for example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test sourcetype=testsourcetype username, Subject 
| eval duration=floor((now()-_time) / 86400)
| table username, Subject, ID, Event, duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;Note: *&lt;/EM&gt;&lt;EM&gt;floor&lt;/EM&gt;** function rounds a number down to the nearest whole integer, use &lt;STRONG&gt;&lt;EM&gt;ceil&lt;/EM&gt;&lt;/STRONG&gt; function to round a number up to the next highest integer.* &lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 06:31:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352520#M104345</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2018-02-01T06:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352521#M104346</link>
      <description>&lt;P&gt;@493669 can you explain what's happening in the evals so I can better grasp it?&lt;/P&gt;

&lt;P&gt;I also would like to compute the duration between another to fields, e.g.  CreationDate - ClosureDate.  Then I would like get the average duration in days for both  "open events" and events that have been closed.  &lt;/P&gt;

&lt;P&gt;Open events would be any events that are not marked as Closed=1&lt;BR /&gt;
Closed event would be any events that are marked as Closed=0&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 02:19:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352521#M104346</guid>
      <dc:creator>johnward4</dc:creator>
      <dc:date>2018-03-08T02:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352522#M104347</link>
      <description>&lt;P&gt;to calculate difference in days you need to convert &lt;CODE&gt;CreationDate&lt;/CODE&gt; and &lt;CODE&gt;ClosureDate&lt;/CODE&gt; into epoch (in seconds) using &lt;CODE&gt;strptime&lt;/CODE&gt; ..If you could provide format of  &lt;CODE&gt;CreationDate&lt;/CODE&gt; and &lt;CODE&gt;ClosureDate&lt;/CODE&gt; then I can help you with exact query...&lt;BR /&gt;
after calculating epoch then subtract these two and then divide by 86400 to get difference in days.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 03:44:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352522#M104347</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-03-08T03:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352523#M104348</link>
      <description>&lt;H2&gt;CreationDate&lt;/H2&gt;

&lt;P&gt;2018-03-07 22:59:30.1&lt;BR /&gt;
2018-03-07 22:27:45.343&lt;/P&gt;

&lt;H2&gt;ClosureDate&lt;/H2&gt;

&lt;P&gt;2018-03-07 22:05:10.843&lt;BR /&gt;
2018-03-07 21:07:57.17   &lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 07:08:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352523#M104348</guid>
      <dc:creator>johnward4</dc:creator>
      <dc:date>2018-03-08T07:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352524#M104349</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;|eval CreationDate=strptime(CreationDate,"%Y-%m-%d %H:%M:%S.%3N"), ClosureDate=strptime(ClosureDate,"%Y-%m-%d %H:%M:%S.%3N")
|eval days=round((CreationDate-ClosureDate)/86400)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 13:07:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352524#M104349</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-03-08T13:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352525#M104350</link>
      <description>&lt;P&gt;Sweet! thanks @493669  Do you have any advice on how to take an average of both fields by GroupName then calculate the combinedaverage?  &lt;/P&gt;

&lt;P&gt;e.g. stats avg(duration), avg(closedduration) by GroupName&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=test sourcetype="test" GroupName=* TestID=* 
| dedup TestID
| eval currentdate= now() 
| convert timeformat="%d %m %Y %H:%M:%S %Z" ctime(currentdate) AS c_time
| eval Event=strftime ("CreationDate", "%d %m %Y %H:%M:%S %Z"),c_time1=c_time
| eval c_time1=strptime(c_time1,"%d %m %Y %H:%M:%S %Z") ,Event1=strptime(Event,"%d %m %Y %H:%M:%S %Z")
| eval duration=('c_time1'-'_time')/(60*60)
| eval CreationDate1=strptime(CreationDate,"%Y-%m-%d %H:%M:%S.%3N"), ClosureDate1=strptime(ClosureDate,"%Y-%m-%d %H:%M:%S.%3N")
| eval closedduration=round((ClosureDate1-CreationDate1)/86400)
| lookup testcategory.csv HD_Nome OUTPUT Difficulty AS Difficulty
| stats avg(duration), avg(closedduration) by GroupName
| rename avg(duration) as avgdur, avg(closedduration) as avgclosed
| eval combinedavg = round(avgdur + avgclosed)
| stats avg(combinedavg) by GroupName
| table avg(duration), GroupName, avg(closedduration), combinedavg, avg(combinedavg)
| sort - avg(combinedavg)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 20:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352525#M104350</guid>
      <dc:creator>johnward4</dc:creator>
      <dc:date>2018-03-08T20:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract two fields containing %m%d%y format time values to get the age of an event?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352526#M104351</link>
      <description>&lt;P&gt;Try this simplified query ...in below query duration and closedduration to be in days so divided by 86400...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=test sourcetype="test" GroupName=* TestID=* 
 | dedup TestID
| eval duration=round((now()-_time) / 86400)
| eval CreationDate1=strptime(CreationDate,"%Y-%m-%d %H:%M:%S.%3N"), ClosureDate1=strptime(ClosureDate,"%Y-%m-%d %H:%M:%S.%3N")
 | eval closedduration=round((ClosureDate1-CreationDate1)/86400)
 | lookup testcategory.csv HD_Nome OUTPUT Difficulty AS Difficulty
| stats avg(duration) as avgdur , avg(closedduration) as avgclosed by GroupName
| eval combinedavg = round((avgdur + avgclosed)/2)
| sort - combinedavg
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 03:38:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-two-fields-containing-m-d-y-format-time-values/m-p/352526#M104351</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-03-09T03:38:25Z</dc:date>
    </item>
  </channel>
</rss>

