<?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: Subtracting two timestamps returning incorrect difference? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564151#M100473</link>
    <description>&lt;P&gt;That didn't return any results for me &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Aug 2021 19:05:17 GMT</pubDate>
    <dc:creator>xoamanda12xo</dc:creator>
    <dc:date>2021-08-20T19:05:17Z</dc:date>
    <item>
      <title>Subtracting two timestamps returning incorrect difference?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564144#M100471</link>
      <description>&lt;P&gt;I am using the splunk field: _time and subtracting my own time field: open_date from the time field. The goal is to get the difference between these two time stamps. For example, one entry in the _time field is: "2021-03-11 11:17:13" and one entry in the open_date field is: "2021-06-07T14:50:42".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running the current query operations:&lt;/P&gt;&lt;P&gt;| eval difference = abs(_time - strptime(open_date, "%Y-%m-%dT%H:%M:%S")) | eval difference = strftime(difference,"%Y-%m-%dT%H:%M:%S")&lt;/P&gt;&lt;P&gt;When running this for the above example entries I get a difference output of "1970-03-29T20:10:19", &amp;nbsp;which is obviously incorrect. What am I doing wrong and how can I get the correct difference between these two fields?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 18:15:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564144#M100471</guid>
      <dc:creator>xoamanda12xo</dc:creator>
      <dc:date>2021-08-20T18:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps returning incorrect difference?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564148#M100472</link>
      <description>&lt;P&gt;I would try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval mytime=strftime(_time,"%Y-%m-%dT%H:%M:%S")
| eval open_date = (strptime(open_date, "%Y-%m-%dT%H:%M:%S")
| eval diff = abs(mytime - open_date) 
| eval difference = strftime(diff,"%Y-%m-%dT%H:%M:%S")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;When you call the _time variable by default it is in UTC so you need to format both fields before running the final equation. Please upvote if this helps! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 18:45:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564148#M100472</guid>
      <dc:creator>astackpole</dc:creator>
      <dc:date>2021-08-20T18:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps returning incorrect difference?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564151#M100473</link>
      <description>&lt;P&gt;That didn't return any results for me &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 19:05:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564151#M100473</guid>
      <dc:creator>xoamanda12xo</dc:creator>
      <dc:date>2021-08-20T19:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting two timestamps returning incorrect difference?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564160#M100474</link>
      <description>&lt;P&gt;Try this! Using now() instead of _time works a lot better from my experience. I was able to test this too so let me know if this works for you then!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval open_date = "2021-06-07T14:50:42"
| eval open=strptime(open_date, "%F")
| eval days=round((now()-open),0)
| table open open_date _time days&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's another Splunk Answer I found that may be helpful too!&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65056" target="_blank" rel="noopener"&gt;https://community.splunk.com/t5/Splunk-Search/Compare-a-date-field-with-current-date/m-p/65056&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 20:58:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Subtracting-two-timestamps-returning-incorrect-difference/m-p/564160#M100474</guid>
      <dc:creator>astackpole</dc:creator>
      <dc:date>2021-08-20T20:58:48Z</dc:date>
    </item>
  </channel>
</rss>

