<?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: find the difference between two date/time values in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176166#M2345</link>
    <description>&lt;P&gt;You cannot compare times that way. You'll need to convert them to &lt;CODE&gt;epoch&lt;/CODE&gt; first. If one of those timestamps are already being used as the timestamp for the event, then the conversion has already been made for that timestamp, and it is availible in the &lt;CODE&gt;_time&lt;/CODE&gt; field. Otherwise you'll need to do the following;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_base_search 
| eval it = strptime(in_time, "%Y-%m-%dT%H:%M:%S.%3N") 
| eval ot = strptime(out_time, "%Y-%m-%dT%H:%M:%S.%3N") 
| eval diff = tostring((ot - it), "duration") 
| table in_time, out_time, diff 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;read more here;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://en.wikipedia.org/wiki/Unix_epoch"&gt;http://en.wikipedia.org/wiki/Unix_epoch&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2013 10:47:21 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2013-12-12T10:47:21Z</dc:date>
    <item>
      <title>find the difference between two date/time values</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176165#M2344</link>
      <description>&lt;P&gt;Hi,  &lt;/P&gt;

&lt;P&gt;I need small help to build a query to find the difference between two date/time values of a log in table format. For example in_time=2013-12-11T22:58:50.797  and out_time=2013-12-11T22:58:51.023.&lt;/P&gt;

&lt;P&gt;tried this query but i didn't get the result.&lt;BR /&gt;
 | eval otime=out_time| eval itime=in_time | eval TimeDiff=otime-itime | table out_time in_time TimeDiff&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:28:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176165#M2344</guid>
      <dc:creator>krishnakishoreg</dc:creator>
      <dc:date>2020-09-28T15:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: find the difference between two date/time values</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176166#M2345</link>
      <description>&lt;P&gt;You cannot compare times that way. You'll need to convert them to &lt;CODE&gt;epoch&lt;/CODE&gt; first. If one of those timestamps are already being used as the timestamp for the event, then the conversion has already been made for that timestamp, and it is availible in the &lt;CODE&gt;_time&lt;/CODE&gt; field. Otherwise you'll need to do the following;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_base_search 
| eval it = strptime(in_time, "%Y-%m-%dT%H:%M:%S.%3N") 
| eval ot = strptime(out_time, "%Y-%m-%dT%H:%M:%S.%3N") 
| eval diff = tostring((ot - it), "duration") 
| table in_time, out_time, diff 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;read more here;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://en.wikipedia.org/wiki/Unix_epoch"&gt;http://en.wikipedia.org/wiki/Unix_epoch&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2013 10:47:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176166#M2345</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-12T10:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: find the difference between two date/time values</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176167#M2346</link>
      <description>&lt;P&gt;Thanks a lot, by doing some change query worked.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2013 16:56:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176167#M2346</guid>
      <dc:creator>krishnakishoreg</dc:creator>
      <dc:date>2013-12-12T16:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: find the difference between two date/time values</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176168#M2347</link>
      <description>&lt;P&gt;feel free to mark the question as answered a/o upvote if it solved your problem. Thanks, K&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2013 19:30:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176168#M2347</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-12T19:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: find the difference between two date/time values</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176169#M2348</link>
      <description>&lt;P&gt;In case anyone was scratching their head like me, the time formats should be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"%Y-%m-%d %H:%M:%S.%3N"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There should be spaces where the 'T's are.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 20:45:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176169#M2348</guid>
      <dc:creator>aszewczyk</dc:creator>
      <dc:date>2016-08-10T20:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: find the difference between two date/time values</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176170#M2349</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I'm in the same scenario, but trying to get the difference from &lt;CODE&gt;CREATED_DATE&lt;/CODE&gt; and &lt;CODE&gt;current timestamp&lt;/CODE&gt;. For that, it is not working.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    base_search  
| eval it = strptime(CREATED_DATE, "%Y-%m-%d %H:%M:%S") 
| eval nowstring=strptime(now(), "%Y-%m-%d %H:%M:%S") 
| eval ticket_duration=tostring((now() - it), "duration" )  
| table DESCRIPTION,CREATED_DATE,TICKET_STATUS,UPDATE_DATE, ticket_duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;PRE&gt;&lt;CODE&gt;base_search  
| convert timeformat='%Y-%m-%dT%H:%M:%S' mktime(CREATED_DATE) mktime(now()  AS  _now) 
| eval duration=(_now-CREATED_DATE)/86400 
|table TTID,MANAGER_NAME,SEVERITY,DESCRIPTION,CREATED_DATE,TICKET_STATUS,UPDATE_DATE, duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In both ways I'm getting  null value,  &lt;CODE&gt;ticket_duration=null&lt;/CODE&gt;&lt;BR /&gt;
Can you please suggest any?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 23:22:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/find-the-difference-between-two-date-time-values/m-p/176170#M2349</guid>
      <dc:creator>nagarajsf</dc:creator>
      <dc:date>2019-10-28T23:22:53Z</dc:date>
    </item>
  </channel>
</rss>

