<?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: Duration calculated incorrectly in Security</title>
    <link>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349868#M8817</link>
    <description>&lt;P&gt;I don't see a negative number when I try the calculation. However, one thing is puzzling me, %I is the hour in a 12 hour clock notation. To uniquely identify the hour wouldn't you also require the AM/PM portion of the timestamp.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2017 16:10:49 GMT</pubDate>
    <dc:creator>davebrooking</dc:creator>
    <dc:date>2017-06-19T16:10:49Z</dc:date>
    <item>
      <title>Duration calculated incorrectly</title>
      <link>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349865#M8814</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;My logs have the start and end time of an event. I am using the below query to calculate duration,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;filter terms&amp;gt; 
| eval epochStartDateTime=strptime(startDate." ".startTime,"%d/%b/%Y %I:%M:%S.%3Q") 
| eval epochEndDateTime=strptime(endDate." ".endTime,"%d/%b/%Y %I:%M:%S.%3Q") 
| eval duration=epochEndDateTime-epochStartDateTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works for all cases except the below,&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;startDate&lt;/STRONG&gt;:  14/Jun/2017 &lt;STRONG&gt;startTime&lt;/STRONG&gt;: 11:57:27.164&lt;BR /&gt;
&lt;STRONG&gt;endDate&lt;/STRONG&gt;:   15/Jun/2017 &lt;STRONG&gt;endTime&lt;/STRONG&gt;: 12:00:48.401&lt;/P&gt;

&lt;P&gt;Duration is returned in negative (duration=-42998.763000).&lt;BR /&gt;
How do I handle this case?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Deepak  &lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:37:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349865#M8814</guid>
      <dc:creator>deepak02</dc:creator>
      <dc:date>2017-06-19T15:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Duration calculated incorrectly</title>
      <link>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349866#M8815</link>
      <description>&lt;P&gt;The format of value of startDate in your question and in strptime do not match (14 June vs %d/%b/%Y). Is that a typo in your question?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:42:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349866#M8815</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-06-19T15:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Duration calculated incorrectly</title>
      <link>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349867#M8816</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;unfortunately I can't provide you with a working solution to this, but I would like to suggest a command I've learned about few days ago. &lt;/P&gt;

&lt;P&gt;It's the &lt;CODE&gt;fieldformat&lt;/CODE&gt; command and it could help you when it comes around working and calculating with time and stuff.&lt;/P&gt;

&lt;P&gt;Here is a link: &lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.3/SearchReference/Fieldformat"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.3/SearchReference/Fieldformat&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 15:47:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349867#M8816</guid>
      <dc:creator>horsefez</dc:creator>
      <dc:date>2017-06-19T15:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Duration calculated incorrectly</title>
      <link>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349868#M8817</link>
      <description>&lt;P&gt;I don't see a negative number when I try the calculation. However, one thing is puzzling me, %I is the hour in a 12 hour clock notation. To uniquely identify the hour wouldn't you also require the AM/PM portion of the timestamp.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 16:10:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349868#M8817</guid>
      <dc:creator>davebrooking</dc:creator>
      <dc:date>2017-06-19T16:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Duration calculated incorrectly</title>
      <link>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349869#M8818</link>
      <description>&lt;P&gt;I believe that your actual test data was 15/Jun/2017 instead of 14/Jun/2017.  That correctly calculates to the numbers you posted, due to the %I hour , which means that "12:00:48.401" is roughly 12 hours before "11:57:27.164", or about -42998 seconds. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval startDate="15/Jun/2017", startTime="11:57:27.164"
| eval endDate="15/Jun/2017", endTime="12:00:48.401"
| eval epochStartDateTime=strptime(startDate." ".startTime,"%d/%b/%Y %I:%M:%S.%3Q") 
| eval epochEndDateTime=strptime(endDate." ".endTime,"%d/%b/%Y %I:%M:%S.%3Q") 
| eval duration=epochEndDateTime-epochStartDateTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you change the format string to  "%d/%b/%Y %H:%M:%S.%3Q", to fix the issue pointed out by @davebrooking, then the calculation will change to 24-hour basis, and will calculate about 200 seconds duration.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2017 16:42:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/Duration-calculated-incorrectly/m-p/349869#M8818</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-06-19T16:42:50Z</dc:date>
    </item>
  </channel>
</rss>

