<?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 you calculate the difference between two different dates? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449676#M127312</link>
    <description>&lt;P&gt;@wagnerlucena,&lt;/P&gt;

&lt;P&gt;In your first search , calculate the difference in epoch (strptime) format before you convert it to string using strftime,&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename fields.created as createdtime, key as Ticket, fields.updated as updatedtime
| eval created=strptime(createdtime,"%Y-%m-%dT%H:%M:%S.%3N")
| eval last_time=strptime(updatedtime,"%Y-%m-%dT%H:%M:%S.%3N")
| eval diff=(last_time-created) | eval diff = round(diff/60/60/24) 
| search Ticket=ACSD-12754 
| eventstats values(Ticket) as Ticket 
| table Ticket,fields.status.name,diff,created, last_time *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Oct 2018 14:11:25 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2018-10-30T14:11:25Z</dc:date>
    <item>
      <title>How do you calculate the difference between two different dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449675#M127311</link>
      <description>&lt;P&gt;HI all,&lt;/P&gt;

&lt;P&gt;I've read many articles in Splunk community to find out how to calculate different dates. I get the correct result putting the date into the eval syntax but no success informing my fields into variables in eval syntax. Can anyone help me solve this problem? &lt;/P&gt;

&lt;P&gt;My log is a JSON, I converted the date with strftime and strptime to get the format as "%d-%B-%y".&lt;/P&gt;

&lt;P&gt;Follow below for my syntaxes, the first one is the one I'm working to solve and second one is the syntax that i got the correct result informing the date instead of field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename fields.created as createdtime, key as Ticket, fields.updated as updatedtime
| eval created=strftime(strptime(createdtime,"%Y-%m-%dT%H:%M:%S.%3N"),"%d-%B-%y")
| eval last_time=strftime(strptime(updatedtime,"%Y-%m-%dT%H:%M:%S.%3N"),"%d-%B-%y")
| eval diff=(last_time-created) | eval diff = round(diff/60/60/24) 
| search Ticket=ACSD-12754 
| eventstats values(Ticket) as Ticket 
| table Ticket,fields.status.name,diff,created, last_time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5999i989C108513EBA0FB/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval created="26-October-18" 
| eval triaged="29-October-18" 
| eval dt_created=strptime(created, "%d-%B-%y") |  eval last_date=strptime(triaged, "%d-%B-%y") 
| eval diff=(last_date-dt_created) 
| eval diff = round(diff/60/60/24)  
| table created triaged diff | dedup created, triaged 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6000iAEA3536795CDD36C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:00:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449675#M127311</guid>
      <dc:creator>wagnerlucena</dc:creator>
      <dc:date>2018-10-30T14:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the difference between two different dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449676#M127312</link>
      <description>&lt;P&gt;@wagnerlucena,&lt;/P&gt;

&lt;P&gt;In your first search , calculate the difference in epoch (strptime) format before you convert it to string using strftime,&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename fields.created as createdtime, key as Ticket, fields.updated as updatedtime
| eval created=strptime(createdtime,"%Y-%m-%dT%H:%M:%S.%3N")
| eval last_time=strptime(updatedtime,"%Y-%m-%dT%H:%M:%S.%3N")
| eval diff=(last_time-created) | eval diff = round(diff/60/60/24) 
| search Ticket=ACSD-12754 
| eventstats values(Ticket) as Ticket 
| table Ticket,fields.status.name,diff,created, last_time *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:11:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449676#M127312</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-30T14:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the difference between two different dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449677#M127313</link>
      <description>&lt;P&gt;Hi @renjith.nair thank you for your answer. &lt;/P&gt;

&lt;P&gt;I converted it into epoch time, but got the same result. I mean, the diff is not being calculating. Take a look the picture.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5998i1B3B3F0313B67BBA/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449677#M127313</guid>
      <dc:creator>wagnerlucena</dc:creator>
      <dc:date>2018-10-30T14:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the difference between two different dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449678#M127314</link>
      <description>&lt;P&gt;@wagnerlucena, that's because your created and last_time are multivalue field.&lt;/P&gt;

&lt;P&gt;Try replacing the variables by&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval created=strptime(mvindex(createdtime,0),"%Y-%m-%dT%H:%M:%S.%3N")
 | eval last_time=strptime(mvindex(updatedtime,0),"%Y-%m-%dT%H:%M:%S.%3N")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:28:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449678#M127314</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-30T14:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the difference between two different dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449679#M127315</link>
      <description>&lt;P&gt;Hi @renjith.nair  you rock! Thanks for support, now i'm able get the difference. I'll adjust my query to retrieve the results that i'm looking for. Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 18:53:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449679#M127315</guid>
      <dc:creator>wagnerlucena</dc:creator>
      <dc:date>2018-10-30T18:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the difference between two different dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449680#M127316</link>
      <description>&lt;P&gt;@wagnerlucena,&lt;BR /&gt;
You are welcome. Glad that it worked. You may upvote the answer/comment if it's useful for others &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 11:26:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449680#M127316</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-10-31T11:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do you calculate the difference between two different dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449681#M127317</link>
      <description>&lt;P&gt;can you please mention the final formula that you have used, I am looking for the same but not able to get the difference between two dates&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 06:51:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-calculate-the-difference-between-two-different-dates/m-p/449681#M127317</guid>
      <dc:creator>abhijitsaoji</dc:creator>
      <dc:date>2019-03-05T06:51:51Z</dc:date>
    </item>
  </channel>
</rss>

