<?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 can I find the difference in days between two timestamps in this format? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263664#M50607</link>
    <description>&lt;P&gt;For the first question I wouldn't use duration in that case, I would simply divide the difference in seconds by 86400 and then use round to round it to the closest integer value. For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search here
| eval diffInSecs = t2 - t1
| eval days = round(diffInSecs/86400, 0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can't do a stats avg of duration because it is a string but you can do an average of the time in seconds and then present that as a duration. Hope that makes sense.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearch
| stats avg(diffInSecs) as avgDiffInSecs
| eval avgDiffInDuration = tostring(avgDiffInSecs , "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 01 Apr 2016 09:35:22 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-04-01T09:35:22Z</dc:date>
    <item>
      <title>How can I find the difference in days between two timestamps in this format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263661#M50604</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I would like to find out the difference in days between two timestamps however the time format is a little weird.&lt;/P&gt;

&lt;P&gt;This is the time format: 2016-03-19T15:05:40Z&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 16:32:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263661#M50604</guid>
      <dc:creator>Makinde</dc:creator>
      <dc:date>2016-03-29T16:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: How can I find the difference in days between two timestamps in this format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263662#M50605</link>
      <description>&lt;P&gt;Probably easier to explain with an example. See below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count
| eval t1_string = "2016-03-19T15:05:40Z"
| eval t2_string = "2016-03-20T16:06:41Z"
| eval t1 = strptime(t1_string, "%Y-%m-%dT%H:%M:%SZ")
| eval t2 = strptime(t2_string, "%Y-%m-%dT%H:%M:%SZ")
| eval diffInSecs = t2 - t1
| eval diffInDuration = tostring(t2 - t1 , "duration")
| table t1_string, t2_string, diff*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;t1_string   t2_string   diffInDuration  diffInSecs
2016-03-19T15:05:40Z    2016-03-20T16:06:41Z    1+01:01:01.000000   90061.000000 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 18:11:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263662#M50605</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-03-29T18:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I find the difference in days between two timestamps in this format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263663#M50606</link>
      <description>&lt;P&gt;Thanks Javiergn&lt;/P&gt;

&lt;P&gt;This seems to work, however how can round up the duration value to the nearest days so instead of 1+01:01:01 how can I round it off to one day and if larger than 12 hrs round it off 2 days&lt;/P&gt;

&lt;P&gt;Secondly I would like to do a stats average of all the duration value, is that possible? something like this:&lt;/P&gt;

&lt;P&gt;... search ... | stats avg(diffInDuration)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2016 18:14:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263663#M50606</guid>
      <dc:creator>Makinde</dc:creator>
      <dc:date>2016-03-30T18:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: How can I find the difference in days between two timestamps in this format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263664#M50607</link>
      <description>&lt;P&gt;For the first question I wouldn't use duration in that case, I would simply divide the difference in seconds by 86400 and then use round to round it to the closest integer value. For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search here
| eval diffInSecs = t2 - t1
| eval days = round(diffInSecs/86400, 0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can't do a stats avg of duration because it is a string but you can do an average of the time in seconds and then present that as a duration. Hope that makes sense.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearch
| stats avg(diffInSecs) as avgDiffInSecs
| eval avgDiffInDuration = tostring(avgDiffInSecs , "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Apr 2016 09:35:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-find-the-difference-in-days-between-two-timestamps-in/m-p/263664#M50607</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-04-01T09:35:22Z</dc:date>
    </item>
  </channel>
</rss>

