<?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 to edit my eval statements to find the difference between Start and Finish times and convert to a human readable format? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202140#M58601</link>
    <description>&lt;P&gt;I tried your suggestions with a change or two:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EVAL StartTime=if(EventType="AGENT_CONNECTED",_time,null()) | EVAL Start_Time=strftime(StartTime, "%H:%M:%S") | EVAL FinishTime=if(EventType="AGENT_ENDED",_time,null()) | EVAL Finish_Time=strftime(FinishTime, "%H:%M:%S") | transaction Start_Time Finish_TIME UserDisplayName MachineName startswith="AGENT_CONNECTED" OR "AGENT_RECONNECTED" endswith="AGENT_ENDED" | EVAL Duration=FinishTime-StartTime | Table UserDisplayName MachineName Start_Time Finish_Time Duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I guess the duration is in seconds, but not truly usable.&lt;/P&gt;

&lt;P&gt;Here is the output for example:&lt;/P&gt;

&lt;P&gt;Start_Time Finish_Time Duration&lt;BR /&gt;
13:55:40  14:09:12  812&lt;BR /&gt;&lt;BR /&gt;
11:20:49  13:48:58  8889&lt;BR /&gt;&lt;BR /&gt;
11:52:35  16:01:53  14958&lt;BR /&gt;&lt;BR /&gt;
11:40:48  15:17:07  12979&lt;BR /&gt;&lt;BR /&gt;
09:59:02  15:45:36  20794&lt;BR /&gt;&lt;BR /&gt;
09:42:48  14:58:08  18920&lt;BR /&gt;&lt;BR /&gt;
16:16:57  16:37:31  1234&lt;BR /&gt;&lt;BR /&gt;
11:58:54  13:45:29  6395&lt;BR /&gt;&lt;BR /&gt;
11:28:13  13:54:58  8805&lt;BR /&gt;&lt;BR /&gt;
09:10:04  15:15:16  21912  &lt;/P&gt;

&lt;P&gt;I then added this to see:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  EVAL duration=FinishTime-StartTime | EVAL Duration=strftime(duration, "%H:%M:%S") |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The below durations seem to have correct minutes and seconds, but not hours.&lt;/P&gt;

&lt;P&gt;Start_Time Finish_Time  Duration&lt;BR /&gt;
13:55:40  14:09:12  19:13:32&lt;BR /&gt;&lt;BR /&gt;
11:20:49  13:48:58  21:28:09&lt;BR /&gt;&lt;BR /&gt;
11:52:35  16:01:53  23:09:18&lt;BR /&gt;&lt;BR /&gt;
11:40:48  15:17:07  22:36:19&lt;BR /&gt;&lt;BR /&gt;
09:59:02  15:45:36  00:46:34&lt;BR /&gt;&lt;BR /&gt;
09:42:48  14:58:08  00:15:20&lt;BR /&gt;&lt;BR /&gt;
16:16:57  16:37:31  19:20:34&lt;BR /&gt;&lt;BR /&gt;
11:58:54  13:45:29  20:46:35&lt;BR /&gt;&lt;BR /&gt;
11:28:13  13:54:58  21:26:45&lt;BR /&gt;&lt;BR /&gt;
09:10:04  15:15:16  01:05:12  &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 09:54:25 GMT</pubDate>
    <dc:creator>thoban</dc:creator>
    <dc:date>2020-09-29T09:54:25Z</dc:date>
    <item>
      <title>How to edit my eval statements to find the difference between Start and Finish times and convert to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202138#M58599</link>
      <description>&lt;P&gt;I'm looking to show the duration of logons through VDI logs.  I convert _time into something better for the Start and Finish Times, but I'm unable to evaluate the difference.&lt;/P&gt;

&lt;P&gt;I have tried to convert the Splunk duration fields back to a "human" readable format, but I have not been successful.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EVAL Start_Time=strftime(if(EventType="AGENT_CONNECTED",_time,null()), "%H:%M:%S") | EVAL Finish_Time=strftime(if(EventType="AGENT_ENDED",_time,null()), "%H:%M:%S") | transaction UserDisplayName MachineName startswith="AGENT_CONNECTED" endswith="AGENT_ENDED" | EVAL Duration=Finish_Time-Start_Time | Table UserDisplayName MachineName Start_Time Finish_Time Duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2016 16:48:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202138#M58599</guid>
      <dc:creator>thoban</dc:creator>
      <dc:date>2016-06-09T16:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statements to find the difference between Start and Finish times and convert to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202139#M58600</link>
      <description>&lt;P&gt;Start_Time and Finish_Time are strings so you can't do math with them.  To get the different between two timestamps, always use epoch form (what's passed in to strftime()).  Something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EVAL startTime=if(EventType="AGENT_CONNECTED",_time,null())| eval Start_Time=strftime(startTime, "%H:%M:%S") | EVAL finishTime=strftime(if(EventType="AGENT_ENDED",_time,null()), | eval Finish_Time=strftime(finishTime,"%H:%M:%S") | transaction UserDisplayName MachineName startswith="AGENT_CONNECTED" endswith="AGENT_ENDED" | EVAL Duration=finishTime-startTime | Table UserDisplayName MachineName Start_Time Finish_Time Duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:55:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202139#M58600</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-09-29T09:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statements to find the difference between Start and Finish times and convert to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202140#M58601</link>
      <description>&lt;P&gt;I tried your suggestions with a change or two:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EVAL StartTime=if(EventType="AGENT_CONNECTED",_time,null()) | EVAL Start_Time=strftime(StartTime, "%H:%M:%S") | EVAL FinishTime=if(EventType="AGENT_ENDED",_time,null()) | EVAL Finish_Time=strftime(FinishTime, "%H:%M:%S") | transaction Start_Time Finish_TIME UserDisplayName MachineName startswith="AGENT_CONNECTED" OR "AGENT_RECONNECTED" endswith="AGENT_ENDED" | EVAL Duration=FinishTime-StartTime | Table UserDisplayName MachineName Start_Time Finish_Time Duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I guess the duration is in seconds, but not truly usable.&lt;/P&gt;

&lt;P&gt;Here is the output for example:&lt;/P&gt;

&lt;P&gt;Start_Time Finish_Time Duration&lt;BR /&gt;
13:55:40  14:09:12  812&lt;BR /&gt;&lt;BR /&gt;
11:20:49  13:48:58  8889&lt;BR /&gt;&lt;BR /&gt;
11:52:35  16:01:53  14958&lt;BR /&gt;&lt;BR /&gt;
11:40:48  15:17:07  12979&lt;BR /&gt;&lt;BR /&gt;
09:59:02  15:45:36  20794&lt;BR /&gt;&lt;BR /&gt;
09:42:48  14:58:08  18920&lt;BR /&gt;&lt;BR /&gt;
16:16:57  16:37:31  1234&lt;BR /&gt;&lt;BR /&gt;
11:58:54  13:45:29  6395&lt;BR /&gt;&lt;BR /&gt;
11:28:13  13:54:58  8805&lt;BR /&gt;&lt;BR /&gt;
09:10:04  15:15:16  21912  &lt;/P&gt;

&lt;P&gt;I then added this to see:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  EVAL duration=FinishTime-StartTime | EVAL Duration=strftime(duration, "%H:%M:%S") |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The below durations seem to have correct minutes and seconds, but not hours.&lt;/P&gt;

&lt;P&gt;Start_Time Finish_Time  Duration&lt;BR /&gt;
13:55:40  14:09:12  19:13:32&lt;BR /&gt;&lt;BR /&gt;
11:20:49  13:48:58  21:28:09&lt;BR /&gt;&lt;BR /&gt;
11:52:35  16:01:53  23:09:18&lt;BR /&gt;&lt;BR /&gt;
11:40:48  15:17:07  22:36:19&lt;BR /&gt;&lt;BR /&gt;
09:59:02  15:45:36  00:46:34&lt;BR /&gt;&lt;BR /&gt;
09:42:48  14:58:08  00:15:20&lt;BR /&gt;&lt;BR /&gt;
16:16:57  16:37:31  19:20:34&lt;BR /&gt;&lt;BR /&gt;
11:58:54  13:45:29  20:46:35&lt;BR /&gt;&lt;BR /&gt;
11:28:13  13:54:58  21:26:45&lt;BR /&gt;&lt;BR /&gt;
09:10:04  15:15:16  01:05:12  &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:54:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202140#M58601</guid>
      <dc:creator>thoban</dc:creator>
      <dc:date>2020-09-29T09:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statements to find the difference between Start and Finish times and convert to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202141#M58602</link>
      <description>&lt;P&gt;Use this as your last eval&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Duration=tostring(duration,"duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2016 18:40:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202141#M58602</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-09T18:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statements to find the difference between Start and Finish times and convert to a human readable format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202142#M58603</link>
      <description>&lt;P&gt;Exactly what was needed!&lt;BR /&gt;
Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 19:19:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statements-to-find-the-difference-between/m-p/202142#M58603</guid>
      <dc:creator>thoban</dc:creator>
      <dc:date>2016-06-09T19:19:41Z</dc:date>
    </item>
  </channel>
</rss>

