<?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: Time Difference In Days in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214618#M62931</link>
    <description>&lt;P&gt;hi,&lt;/P&gt;

&lt;P&gt;this option display the difference in days&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval days_since = (now() - last_seen) / 86400
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_audit action=edit_user operation=edit OR operation=create
  | rename object as user
  | stats max(timestamp) as "created" by user
  | eval createddate=strptime(created, "%m-%d-%Y %H:%M:%S")
  | eval testtime=now() 
  | eval days_since = (testtime - createddate) / 86400
  | eval diff = tostring((testtime - createddate), "duration")  
  |eval u = diff / 86400 
  | fields createddate testtime diff u days_since
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 22 Feb 2016 09:19:32 GMT</pubDate>
    <dc:creator>gyslainlatsa</dc:creator>
    <dc:date>2016-02-22T09:19:32Z</dc:date>
    <item>
      <title>Time Difference In Days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214616#M62929</link>
      <description>&lt;P&gt;Hi, I wonder whether someone may be able to help me please.&lt;/P&gt;

&lt;P&gt;I'm trying to put together a query which calculates the difference between the current date and a "Created Date". If you could have  a look at the query below please, I've converted the "Created Date" to epoch time e.g. 1455700768.000000 but when I list the current date it's shown as 1456130889. So then when I try to find the difference, the query is extracting results such as 13+08:48:09.000000.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_audit action=edit_user operation=edit OR operation=create
 | rename object as user
 | stats max(timestamp) as "created" by user
 | eval createddate=strptime(created, "%m-%d-%Y %H:%M:%S")
 | eval testtime=now() 
 | eval diff = tostring((testtime - createddate), "duration")         
 | fields createddate testtime diff
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Could someone possible look at this please and let me know where I've gone wrong and how I can calculate the difference in days between the current date and the "Created Date".&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 08:51:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214616#M62929</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2016-02-22T08:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference In Days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214617#M62930</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;13+08:48:09.000000 is the difference in days (13), hours (08), minutes (48), seconds (09) and microseconds. &lt;/P&gt;

&lt;P&gt;If you just need the days you have several options:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;use regex to extract 13 from the above&lt;/LI&gt;
&lt;LI&gt;Divide the time difference in epoch between 86400 and round it. &lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Hope that helps. &lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 09:12:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214617#M62930</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-22T09:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference In Days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214618#M62931</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;

&lt;P&gt;this option display the difference in days&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval days_since = (now() - last_seen) / 86400
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_audit action=edit_user operation=edit OR operation=create
  | rename object as user
  | stats max(timestamp) as "created" by user
  | eval createddate=strptime(created, "%m-%d-%Y %H:%M:%S")
  | eval testtime=now() 
  | eval days_since = (testtime - createddate) / 86400
  | eval diff = tostring((testtime - createddate), "duration")  
  |eval u = diff / 86400 
  | fields createddate testtime diff u days_since
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2016 09:19:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214618#M62931</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2016-02-22T09:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference In Days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214619#M62932</link>
      <description>&lt;P&gt;Hi, thank you for coming back to me with the guidance.&lt;/P&gt;

&lt;P&gt;Kind Regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 09:45:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214619#M62932</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2016-02-22T09:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Time Difference In Days</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214620#M62933</link>
      <description>&lt;P&gt;Hi, thank you very much for taking the time to come back to me with this.&lt;/P&gt;

&lt;P&gt;In addition  to the suggestion made by @javiergn about rounding, this works as required.&lt;/P&gt;

&lt;P&gt;Kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 09:46:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Time-Difference-In-Days/m-p/214620#M62933</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2016-02-22T09:46:23Z</dc:date>
    </item>
  </channel>
</rss>

