<?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: Calculating hours since event in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462621#M79832</link>
    <description>&lt;P&gt;You're seeing decimal time, instead of "traditional" time - 30.95 hours is 30 hours, 57 minutes&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2019 13:23:03 GMT</pubDate>
    <dc:creator>wmyersas</dc:creator>
    <dc:date>2019-10-17T13:23:03Z</dc:date>
    <item>
      <title>Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462615#M79826</link>
      <description>&lt;P&gt;I am attempting to calculate hours since an event occurred, however, the calculated time shows decimals including .6 to .9 between hour values.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc 
| eval time_difference=(now() - _time) 
| eval time_in_hours=(time_difference/60) 
| eval Hours_elapsed=round(time_in_hours/60,2) 
| eval Time=strftime(_time, "%Y-%m-%d %H:%M:%S") 
| table Time Hours_elapsed 
| sort - Hours_elapsed
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's an example of the output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time                   Hours_elapsed
2019-10-16 05:39:02 22.96
2019-10-16 05:39:19 22.96
2019-10-16 05:39:14 22.96
2019-10-16 05:48:48 22.80
2019-10-16 05:48:47 22.80
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've attempted to calculate the difference of  now() and _time in epoch and then do an eval to calculate the hours, but have had no luck.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 11:36:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462615#M79826</guid>
      <dc:creator>geoffmoraes</dc:creator>
      <dc:date>2019-10-17T11:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462616#M79827</link>
      <description>&lt;P&gt;looks like you are doing fine ...&lt;BR /&gt;
epoch is in seconded and you are calculating hours when dividing in 60 ...&lt;/P&gt;

&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 increment=1h 
| eval _time = starttime 
| eval  now_time = now()
| table now_time _time
| eval difference_in_seconds = now_time - _time
| eval difference_in_hours = round(difference_in_seconds / 3600, 2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 11:54:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462616#M79827</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-10-17T11:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462617#M79828</link>
      <description>&lt;P&gt;Thanks, but it still shows hours with minutes greater than 59. The expected output is that the hour would increment after the minute crosses 59.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;now_time    _time   difference_in_hours difference_in_seconds
1571313436  2019-10-16 00:00    30.95   111436
1571313436  2019-10-16 01:00    29.95   107836
1571313436  2019-10-16 02:00    28.95   10423
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 12:02:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462617#M79828</guid>
      <dc:creator>geoffmoraes</dc:creator>
      <dc:date>2019-10-17T12:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462618#M79829</link>
      <description>&lt;P&gt;yup ...&lt;BR /&gt;
i guess this is what you want:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 increment=1h 
| eval _time = starttime 
| eval  now_time = now()
| table now_time _time
| eval difference_in_seconds = now_time - _time
| eval difference_in_hours_min_sec = tostring(difference_in_seconds, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 12:27:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462618#M79829</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-10-17T12:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462619#M79830</link>
      <description>&lt;P&gt;It's not showing "minutes greater than 59"&lt;/P&gt;

&lt;P&gt;The "difference in hours" column is showing you &lt;EM&gt;decimal&lt;/EM&gt; "time"&lt;/P&gt;

&lt;P&gt;30.95 hours is 30 hours, 57 minutes (.95 hours = 57 minutes)&lt;/P&gt;

&lt;P&gt;There's nothing wrong with the displayed values - unless you want them in hh:mm format&lt;/P&gt;

&lt;P&gt;Then you should do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval seconds=107836
| eval intermediate=round(seconds/3600,2)
| rex field=intermediate "(?&amp;lt;hh&amp;gt;\d+)\.(?&amp;lt;mm&amp;gt;\d+)"
| eval mm=round((mm*60)/100)
| eval hhmm=hh+":"+mm
| table *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which will yield:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hh | hhmm  | intermediate | mm | seconds
29 | 29:57 | 29.95        | 57 | 107836
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 12:31:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462619#M79830</guid>
      <dc:creator>wmyersas</dc:creator>
      <dc:date>2019-10-17T12:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462620#M79831</link>
      <description>&lt;P&gt;You're not getting minute values greater than 59 - you're seeing "decimal time"&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 12:32:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462620#M79831</guid>
      <dc:creator>wmyersas</dc:creator>
      <dc:date>2019-10-17T12:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462621#M79832</link>
      <description>&lt;P&gt;You're seeing decimal time, instead of "traditional" time - 30.95 hours is 30 hours, 57 minutes&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 13:23:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462621#M79832</guid>
      <dc:creator>wmyersas</dc:creator>
      <dc:date>2019-10-17T13:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462622#M79833</link>
      <description>&lt;P&gt;Yes! this is perfect &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;
Thanks adonio! &lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 04:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462622#M79833</guid>
      <dc:creator>geoffmoraes</dc:creator>
      <dc:date>2019-10-18T04:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating hours since event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462623#M79834</link>
      <description>&lt;P&gt;Thanks! I didn't think about decimal "time". It makes sense now. &lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 04:33:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Calculating-hours-since-event/m-p/462623#M79834</guid>
      <dc:creator>geoffmoraes</dc:creator>
      <dc:date>2019-10-18T04:33:44Z</dc:date>
    </item>
  </channel>
</rss>

