<?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 calculate the difference in minutes/seconds between two timestamps in a human readable format? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258130#M49594</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have similar question and your response was with regards to two different fields but in my case we have only single timestamp field but there are two logs with two different timestamps in that field. How to calculate the difference? Can you kindly help.&lt;/P&gt;

&lt;P&gt;See below sample of my logs: &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;11:01:17.876 AM 2019-04-03&lt;/STRONG&gt; tid:XG5HNBNsbPp8uZis90UWNl9vnqQ DEBUG [org.sourceid.util.log.internal.TrackingIdSupport] [cross-reference-message] entityid:&lt;STRONG&gt;ApplicationName&lt;/STRONG&gt; subject:&lt;STRONG&gt;null&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;2019-04-03 11:01:26,579&lt;/STRONG&gt; tid:XG5HNBNsbPp8uZis90UWNl9vnqQ DEBUG [org.sourceid.util.log.internal.TrackingIdSupport] [cross-reference-message] &lt;STRONG&gt;entityid:ApplicationName&lt;/STRONG&gt; subject:&lt;STRONG&gt;JohnDoe&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;The difference between two logs is the time stamp and subject value where in the first log the subject is null and in the second the subject is user id.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2019 18:24:42 GMT</pubDate>
    <dc:creator>rakeshyv0807</dc:creator>
    <dc:date>2019-04-03T18:24:42Z</dc:date>
    <item>
      <title>How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258127#M49591</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;Submit Date / Creation Date Time Stamp  Incident Response Date Time
09/14/2016 01:14 AM                    09/14/2016 01:19 AM
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was searching many scenarios in the SPLUNK community, but was not able to find a solution for this. We need to find the difference between the two timestamps above, and I need to display the output in minutes, seconds etc.&lt;/P&gt;

&lt;P&gt;Is it possible? &lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 11:03:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258127#M49591</guid>
      <dc:creator>rijinc</dc:creator>
      <dc:date>2016-11-30T11:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258128#M49592</link>
      <description>&lt;P&gt;Yes, it is possible.&lt;/P&gt;

&lt;P&gt;Without an actual sample of the entire event, this may be slightly off.  Also, I don't know if you have it in fields or not, nor what fields it may be.  As I look at what you have, I'm going to hope you have two fields, a "submit date time stamp" and a "incident response date time".  This is highly likely to be wrong.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... your base search here ... 
| eval submit=strptime(submit_date, "%m/%d/%Y %I:%M %p") 
| eval response=strptime(response_date, "%m/%d/%Y %I:%M %p")
| eval difference=response-submit | eval diff_in_minutes=difference/60
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You will have to fix the fieldnames (submit_date, response_date) or reply with more information about that.&lt;/P&gt;

&lt;P&gt;That uses eval strptime to convert the text strings into actual dates/times in unix epoch.  That's just seconds, so we subtract them to get the difference and divide by 60 to get minutes.&lt;/P&gt;

&lt;P&gt;Here's a run-anywhere example where I create the two fields, then perform the above calculations on them.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | stats count | eval submit_date="09/14/2016 01:14 AM" | eval response_date="09/14/2016 01:19 AM"
| eval submit=strptime(submit_date, "%m/%d/%Y %I:%M %p") 
| eval response=strptime(response_date, "%m/%d/%Y %I:%M %p")
| eval difference=response-submit | eval diff_in_minutes=difference/60
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note if you really don't need the difference in seconds you could just simplify:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval submit=strptime(submit_date, "%m/%d/%Y %I:%M %p") 
| eval response=strptime(response_date, "%m/%d/%Y %I:%M %p")
| eval diff_in_minutes=(response-submit)/60
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Happy Splunking!&lt;BR /&gt;
-Rich&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:57:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258128#M49592</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2020-09-29T11:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258129#M49593</link>
      <description>&lt;P&gt;You have to convert the time to epochtime before you calculate difference. Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... | eval submit=strptime("Submit Date / Creation Date Time Stamp", "%m/%d/%Y %H:%M %p") | eval response=strptime("Incident Response Date Time", "%m/%d/%Y %H:%M %p") | eval time_diff=response-submit | eval time_diff=tostring(time_diff, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Nov 2016 12:37:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258129#M49593</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-11-30T12:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258130#M49594</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have similar question and your response was with regards to two different fields but in my case we have only single timestamp field but there are two logs with two different timestamps in that field. How to calculate the difference? Can you kindly help.&lt;/P&gt;

&lt;P&gt;See below sample of my logs: &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;11:01:17.876 AM 2019-04-03&lt;/STRONG&gt; tid:XG5HNBNsbPp8uZis90UWNl9vnqQ DEBUG [org.sourceid.util.log.internal.TrackingIdSupport] [cross-reference-message] entityid:&lt;STRONG&gt;ApplicationName&lt;/STRONG&gt; subject:&lt;STRONG&gt;null&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;2019-04-03 11:01:26,579&lt;/STRONG&gt; tid:XG5HNBNsbPp8uZis90UWNl9vnqQ DEBUG [org.sourceid.util.log.internal.TrackingIdSupport] [cross-reference-message] &lt;STRONG&gt;entityid:ApplicationName&lt;/STRONG&gt; subject:&lt;STRONG&gt;JohnDoe&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;The difference between two logs is the time stamp and subject value where in the first log the subject is null and in the second the subject is user id.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 18:24:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/258130#M49594</guid>
      <dc:creator>rakeshyv0807</dc:creator>
      <dc:date>2019-04-03T18:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699909#M115926</link>
      <description>&lt;P&gt;hi&lt;BR /&gt;I have a similar problem&lt;BR /&gt;Tried this solution and I get an empty field&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|eval end_time = strptime(end_time_epoch, "%Y:%m:%d %H:%M:%S:%N")
|eval time_epoch = strptime(now(), "%Y:%m:%d %H:%M:%S")
|eval diff = (end_time-time_epoch)/60&lt;/LI-CODE&gt;&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/205010"&gt;@Richfez&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 08:44:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699909#M115926</guid>
      <dc:creator>Bracha</dc:creator>
      <dc:date>2024-09-24T08:44:32Z</dc:date>
    </item>
    <item>
      <title>How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699911#M115929</link>
      <description>&lt;P&gt;I'm trying to calculate the minute difference between two times&lt;BR /&gt;and get an empty field&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.........base search here.........
|eval end_time = strptime(end_time_epoch, "%Y:%m:%d %H:%M:%S:%N")
|eval time_epoch = strptime(now(), "%Y:%m:%d %H:%M:%S")
|eval diff = (end_time-time_epoch)/60&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 08:58:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699911#M115929</guid>
      <dc:creator>Bracha</dc:creator>
      <dc:date>2024-09-24T08:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699912#M115930</link>
      <description>&lt;P&gt;If something doesn't work as you expect step back and check if you're getting right data in to get right data out.&lt;/P&gt;&lt;P&gt;1. After you eval your end_time, does it conatin a proper numerical epoch timestamp?&lt;/P&gt;&lt;P&gt;2. The time_epoch will most definitely _not_ contain proper epoch timestamp. The now() function itself returns what you need. There's no need to strptime() it. In fact it will only break its value since you can't parse a number using your provided time format.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2024 09:28:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699912#M115930</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-24T09:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699919#M115933</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.........base search here.........
|end_time = 2024-09-24 08:17:13.014337+00:00
|eval end_time = strptime(end_time_epoch, "%Y:%m:%d %H:%M:%S")
|eval _time = now()
|eval time_epoch = strptime(time_epoch, "%Y:%m:%d %H:%M:%S")
|eval diff = (time_epoch-end_time)/60&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 24 Sep 2024 10:36:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/699919#M115933</guid>
      <dc:creator>Bracha</dc:creator>
      <dc:date>2024-09-24T10:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference in minutes/seconds between two timestamps in a human readable format?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/700435#M115993</link>
      <description>Hi&lt;BR /&gt;As this is quite old thread, please create a new question to get answer. I suppose that most of us, didn't read and try to find new comments/questions from old and answered threads.&lt;BR /&gt;&lt;BR /&gt;Based on field name you try to convert epoch time to epoch?</description>
      <pubDate>Sat, 28 Sep 2024 15:38:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-calculate-the-difference-in-minutes-seconds-between-two/m-p/700435#M115993</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-09-28T15:38:04Z</dc:date>
    </item>
  </channel>
</rss>

