<?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: subtraction using eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60096#M180115</link>
    <description>&lt;P&gt;Help, my eval subtraction is not working:&lt;BR /&gt;
| convert ctime(_time) AS time&lt;BR /&gt;
| eval TID=if(Type=="Inbound",obj_type,corrID) &lt;BR /&gt;
| eval inboundTime=if(Type=="Inbound",time,null())&lt;BR /&gt;
| eval outboundTime=if(Type=="Outbound",time,null())&lt;BR /&gt;
| eval ResponseTime=strptime(outboundTime,"%Y%m%d %H:%M:%S.%N")-strptime(inboundTime,"%Y%m%d %H:%M:%S.%N")&lt;BR /&gt;
| stats values(inboundTime) AS starttime values(outboundTime) AS endtime values(ResponseTime) as ResponseTime  by TID&lt;/P&gt;

&lt;P&gt;i even tried &lt;BR /&gt;
| eval ResponseTime=outboundTime-inboundTime&lt;/P&gt;

&lt;P&gt;but there's no output&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 03:45:44 GMT</pubDate>
    <dc:creator>chiennylin</dc:creator>
    <dc:date>2020-09-30T03:45:44Z</dc:date>
    <item>
      <title>subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60086#M180105</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have two fields : In-Time and Out-Time&lt;BR /&gt;
Here is some sample entries&lt;/P&gt;

&lt;P&gt;In-Time     Out-Time&lt;/P&gt;

&lt;P&gt;8:33         17:39&lt;/P&gt;

&lt;P&gt;8:44         17:45&lt;/P&gt;

&lt;P&gt;8:83         17:50&lt;/P&gt;

&lt;P&gt;Here i wanted to subtract Out-Time with In-Time  and display the result as new field&lt;/P&gt;

&lt;P&gt;I tried with the below query: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="sample" | eval Newfield=(Out_Time - In_Time) | table Newfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But if i do so ,its not generating the output(showing blank).Is it because of the ":" in between the time ? how this can be done?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 09:25:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60086#M180105</guid>
      <dc:creator>ChhayaV</dc:creator>
      <dc:date>2013-09-11T09:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60087#M180106</link>
      <description>&lt;P&gt;Hi ChhayaV&lt;/P&gt;

&lt;P&gt;you can use the &lt;CODE&gt;convert&lt;/CODE&gt; command on &lt;CODE&gt;Out_Time&lt;/CODE&gt; and &lt;CODE&gt;In_Time&lt;/CODE&gt; to do your &lt;CODE&gt;eval&lt;/CODE&gt;, take a look at the &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.4/SearchReference/convert#Examples" target="_blank"&gt;examples in docs&lt;/A&gt;. &lt;BR /&gt;
After some testing and proofing, this works for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="sample" | convert dur2sec(Out_Time) dur2sec(In_Time) | eval diff=(Out_Time - In_Time) | eval Newfield=tostring(diff, "duration") | table Newfield
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This was tested and it will convert Out_Time and In_Time into second values, the eval will substract it and the last eval will revert it into HH:MM format.&lt;/P&gt;

&lt;P&gt;hope it works and helps&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:45:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60087#M180106</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2020-09-28T14:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60088#M180107</link>
      <description>&lt;P&gt;Yes,tried with the same thing but itime column values are coming blank.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 10:18:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60088#M180107</guid>
      <dc:creator>ChhayaV</dc:creator>
      <dc:date>2013-09-11T10:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60089#M180108</link>
      <description>&lt;P&gt;Can we use two convert statements in a single search query (as we have used in the above example)?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 10:33:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60089#M180108</guid>
      <dc:creator>ChhayaV</dc:creator>
      <dc:date>2013-09-11T10:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60090#M180109</link>
      <description>&lt;P&gt;yes we can and see my update, did some tests and this works fine for me.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 11:01:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60090#M180109</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2013-09-11T11:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60091#M180110</link>
      <description>&lt;P&gt;You'll have to do it manually I think. According to the docs, &lt;CODE&gt;mstime()&lt;/CODE&gt; will deal with MM:SS.SSS, not with HH:MM (which is what I suspect you are using).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=In_Time "(?&amp;lt;in_h&amp;gt;\d+):(?&amp;lt;in_m&amp;gt;\d+)" 
| rex field=Out_Time "(?&amp;lt;out_h&amp;gt;\d+):(?&amp;lt;out_m&amp;gt;\d+)" 
| eval in_s = (in_h * 3600) + (in_m * 60) 
| eval out_s = (out_h * 3600) + (out_m * 60) 
| eval diff = out_s - in_s
| eval tot_h = floor(diff/3600)
| eval diff = diff - (tot_h * 3600)
| eval tot_m = diff/60 
| eval Duration = tot_h . ":" . tot_m
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or you could do some clever manipulation with &lt;CODE&gt;convert dur2sec(field)&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt;;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| convert dur2sec(In_Time) dur2sec(Out_Time) 
| eval dur_in_sec = Out_Time - In_Time
| eval Duration = strftime(dur_in_sec, "%H:%M")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which I have not tested. Techically &lt;CODE&gt;Duration&lt;/CODE&gt; would be a timestamp sometime in Januray 1st, 1970 - but since you only extract the hour:minute part, that would be irrelevant.&lt;/P&gt;

&lt;P&gt;Hope this helps (and that it works),&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 11:03:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60091#M180110</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-11T11:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60092#M180111</link>
      <description>&lt;P&gt;Hi /k, see my update came up with the same in the end - dur2sec works and mstime() fails because of the missing MM:SS.SSS format&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 11:07:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60092#M180111</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2013-09-11T11:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60093#M180112</link>
      <description>&lt;P&gt;Hi MuS! Yup, seems right. Took me a few minutes to write that down. &lt;CODE&gt;tostring()&lt;/CODE&gt; also seems like a more intuitive idea than &lt;CODE&gt;strftime()&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 11:23:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60093#M180112</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-09-11T11:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60094#M180113</link>
      <description>&lt;P&gt;I don't think strftime is correct, either: try "| stats count | eval foo=strftime(1, "%H:%M")". I'm in eastern daylight time (-0500), and I get "19:00".&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 13:53:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60094#M180113</guid>
      <dc:creator>sowings</dc:creator>
      <dc:date>2013-09-11T13:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60095#M180114</link>
      <description>&lt;P&gt;Hi , &lt;BR /&gt;
source="dbmon-tail://idwarehouse/idw_account" application=TFAYD  [|inputlookup execSSO.csv |rename sso as owner] |eval exp_date=strftime(relative_time(strptime(lastPasswordChange,"%Y-%m-%d %H:%M:%S"),"+90d"), "%Y-%m-%d %H:%M:%S") |eval CurrentTime=strftime(now(), "%Y-%m-%d %H:%M:%S") |rex field=exp_date "(?\d+) (?\d+):(?\d+)"    | rex field=CurrentTime  "(?\d+) (?\d+):(?\d+)"  | eval in_s =  (in_d *86400)+(in_h * 3600) + (in_m * 60)  | eval out_s = (out_d * 86400)+(out_h * 3600) + (out_m * 60) | eval diff = in_s  - out_s  |eval tot_d = floor(diff/86400) |eval diff = diff - (tot_d * 86400)  | eval tot_h = floor(diff/3600) | eval diff = diff - (tot_h * 3600) |eval tot_m = (diff/60)       | eval duration = tot_d . ":" . tot_h . ":" . tot_m&lt;/P&gt;

&lt;P&gt;I tried the above query , it is working good , but month wise result is wrong .&lt;/P&gt;

&lt;P&gt;i want to minux two field ,  it is exp_date - CurrentTime &lt;/P&gt;

&lt;P&gt;my output , &lt;BR /&gt;
CurrentTime =2014-10-09 13:19:55&lt;BR /&gt;
application =TFAYD&lt;BR /&gt;
duration =15:5:43&lt;BR /&gt;
exp_date =2014-12-24 19:02:04&lt;BR /&gt;
in_d =24&lt;BR /&gt;
in_h =19&lt;BR /&gt;
in_m =02&lt;BR /&gt;
in_s =2142120&lt;BR /&gt;
lastPasswordChange =2014-09-25 19:02:04&lt;BR /&gt;
out_d =09&lt;BR /&gt;
out_h =13&lt;BR /&gt;
out_m =19&lt;BR /&gt;
out_s =825540&lt;BR /&gt;
owner =206046611&lt;BR /&gt;
refreshedDate =2014-10-09 12:26:05&lt;BR /&gt;
sourcetype =mysql&lt;BR /&gt;
tot_d =15&lt;BR /&gt;
tot_h =5&lt;BR /&gt;
tot_m =43 &lt;/P&gt;

&lt;P&gt;in_d - out_d ,  24 -9 = 15 (tot_d) ....  but it is wrong ... &lt;/P&gt;

&lt;P&gt;2014-12-24 19:02:04     (exp_date) -  (CurrentTime ) 2014-10-09 13:19:55   .... it is only doing minus ... 24-9 ... not month wise ...&lt;/P&gt;

&lt;P&gt;Thank u ...&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Siraj&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:50:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60095#M180114</guid>
      <dc:creator>siraj198204</dc:creator>
      <dc:date>2020-09-28T17:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60096#M180115</link>
      <description>&lt;P&gt;Help, my eval subtraction is not working:&lt;BR /&gt;
| convert ctime(_time) AS time&lt;BR /&gt;
| eval TID=if(Type=="Inbound",obj_type,corrID) &lt;BR /&gt;
| eval inboundTime=if(Type=="Inbound",time,null())&lt;BR /&gt;
| eval outboundTime=if(Type=="Outbound",time,null())&lt;BR /&gt;
| eval ResponseTime=strptime(outboundTime,"%Y%m%d %H:%M:%S.%N")-strptime(inboundTime,"%Y%m%d %H:%M:%S.%N")&lt;BR /&gt;
| stats values(inboundTime) AS starttime values(outboundTime) AS endtime values(ResponseTime) as ResponseTime  by TID&lt;/P&gt;

&lt;P&gt;i even tried &lt;BR /&gt;
| eval ResponseTime=outboundTime-inboundTime&lt;/P&gt;

&lt;P&gt;but there's no output&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:45:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60096#M180115</guid>
      <dc:creator>chiennylin</dc:creator>
      <dc:date>2020-09-30T03:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60097#M180116</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;. . .
| stats values(inboundTime) AS starttime values(outboundTime) AS endtime values(ResponseTime) as ResponseTime by TID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this result is &lt;CODE&gt;starttime&lt;/CODE&gt; , &lt;CODE&gt;endtime&lt;/CODE&gt; , &lt;CODE&gt;ResponseTime&lt;/CODE&gt;  and &lt;CODE&gt;TID&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval ResponseTime=outboundTime-inboundTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;both fields are nothing.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 10:15:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60097#M180116</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-20T10:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60098#M180117</link>
      <description>&lt;P&gt;the start and end have time. but when i do this:  | eval ResponseTime=outboundTime-inboundTime&lt;BR /&gt;
there is no result. &lt;BR /&gt;
here's the sample:&lt;BR /&gt;
TID starttime   endtime ResponseTime&lt;BR /&gt;
0b44ffc9-8e92-44a0-b487-da9acba0bc52    01/21/2020 00:12:45.168 01/21/2020 00:12:45.362&lt;BR /&gt;&lt;BR /&gt;
0d501b27-ad34-4481-bc16-7c029baa8bec    01/21/2020 00:10:56.951 01/21/2020 00:10:57.293  &lt;/P&gt;

&lt;P&gt;there's no response time by simply eval ResponseTime=outbound-inbound&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 00:24:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60098#M180117</guid>
      <dc:creator>chiennylin</dc:creator>
      <dc:date>2020-01-21T00:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: subtraction using eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60099#M180118</link>
      <description>&lt;P&gt;your &lt;CODE&gt;starttime&lt;/CODE&gt; and &lt;CODE&gt;endtime&lt;/CODE&gt; are both &lt;STRONG&gt;STRING&lt;/STRONG&gt; because &lt;CODE&gt;| convert ctime(_time) AS time&lt;/CODE&gt;&lt;BR /&gt;
String cannot be calculated.&lt;/P&gt;

&lt;P&gt;please convert both to UNIX epoch time.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2020 10:40:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/subtraction-using-eval/m-p/60099#M180118</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-21T10:40:03Z</dc:date>
    </item>
  </channel>
</rss>

