<?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: calculate Difference between 2 time fields  is not working. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/calculate-Difference-between-2-time-fields-is-not-working/m-p/502056#M139754</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;index=s_iss sourcetype=S_AD Name=*
| eval Last_Date = "2019-09-28 17:09:19"
| eval diff=_time - strptime(Last_Date,"%F %T")
| eval Last_Date=mvindex(split(Last_Date," "),0)
| table _time diff Name Last_Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Why do you calculate  &lt;CODE&gt;now()&lt;/CODE&gt; and &lt;EM&gt;Last_Date&lt;/EM&gt;? &lt;BR /&gt;
It is fixed value.&lt;/P&gt;

&lt;P&gt;This query aims to calculate the &lt;EM&gt;diff&lt;/EM&gt; between &lt;EM&gt;_time&lt;/EM&gt; and &lt;EM&gt;Last_Date&lt;/EM&gt;  .&lt;BR /&gt;
How about this?&lt;/P&gt;</description>
    <pubDate>Sat, 23 May 2020 22:51:13 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-05-23T22:51:13Z</dc:date>
    <item>
      <title>calculate Difference between 2 time fields  is not working.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-Difference-between-2-time-fields-is-not-working/m-p/502054#M139752</link>
      <description>&lt;P&gt;I tried to difference between 2 dates. It is not working properly.&lt;/P&gt;

&lt;P&gt;Here is my query,&lt;/P&gt;

&lt;P&gt;index=s_iss sourcetype=S_AD | fillnull value="" |eval Last_Date="2019-09-28 17:09:19.0"|eval _time="2019-05-21 4:55:00.143" | eval Last_Date=strftime(strptime(Last_Date,"%Y-%m-%d %H:%M:%S.%Q"),"%Y-%m-%d") | eval _time = strptime(_time, "%Y-%m-%d")  | eval diff = ( _time - Last_Date)|stats count by Name,Last_Date,_time,diff&lt;/P&gt;

&lt;P&gt;I need the time difference between Last_date and now() and display as Date.&lt;BR /&gt;
Can someone help me out.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:29:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-Difference-between-2-time-fields-is-not-working/m-p/502054#M139752</guid>
      <dc:creator>nivethainspire_</dc:creator>
      <dc:date>2020-09-30T05:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: calculate Difference between 2 time fields  is not working.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-Difference-between-2-time-fields-is-not-working/m-p/502055#M139753</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/122614"&gt;@nivethainspire_&lt;/a&gt;07,&lt;BR /&gt;
in you example _time is a variable that you need to convert in epochtime (with strptime), in real events, you don't need to do this convertion because _time is already in epochtime.&lt;/P&gt;

&lt;P&gt;Then, in your example,  you don't calculate the difference between now and Last_Date but the difference between  _time and Last_Date.&lt;BR /&gt;
Then if you want to use _time in stats, you have to group values (using bin command) before stats or you have to use timechart command.&lt;/P&gt;

&lt;P&gt;So, if you want the difference between Last_Date and now, you could try something like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=s_iss sourcetype=S_AD 
| fillnull value="" 
| eval diff=now()-strptime(Last_Date,"%Y-%m-%d %H:%M:%S.%Q")
| timechart span=1h latest(diff) AS date by Name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:29:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-Difference-between-2-time-fields-is-not-working/m-p/502055#M139753</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2020-09-30T05:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: calculate Difference between 2 time fields  is not working.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-Difference-between-2-time-fields-is-not-working/m-p/502056#M139754</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=s_iss sourcetype=S_AD Name=*
| eval Last_Date = "2019-09-28 17:09:19"
| eval diff=_time - strptime(Last_Date,"%F %T")
| eval Last_Date=mvindex(split(Last_Date," "),0)
| table _time diff Name Last_Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Why do you calculate  &lt;CODE&gt;now()&lt;/CODE&gt; and &lt;EM&gt;Last_Date&lt;/EM&gt;? &lt;BR /&gt;
It is fixed value.&lt;/P&gt;

&lt;P&gt;This query aims to calculate the &lt;EM&gt;diff&lt;/EM&gt; between &lt;EM&gt;_time&lt;/EM&gt; and &lt;EM&gt;Last_Date&lt;/EM&gt;  .&lt;BR /&gt;
How about this?&lt;/P&gt;</description>
      <pubDate>Sat, 23 May 2020 22:51:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-Difference-between-2-time-fields-is-not-working/m-p/502056#M139754</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-05-23T22:51:13Z</dc:date>
    </item>
  </channel>
</rss>

