<?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 find the time difference in days between the _time of an event and the current time? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172806#M49561</link>
    <description>&lt;P&gt;There are two &lt;CODE&gt;eval&lt;/CODE&gt; functions for this, &lt;CODE&gt;now()&lt;/CODE&gt; and &lt;CODE&gt;time()&lt;/CODE&gt;. The major distinction is that &lt;CODE&gt;now()&lt;/CODE&gt; will be stable over a long-running search while &lt;CODE&gt;time()&lt;/CODE&gt; will yield a potentially new timestamp for every event/row/invocation... usually you'll want &lt;CODE&gt;now()&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats latest(_time) as last_seen | eval days_since = (now() - last_seen) / 86400 | eval duration_since = tostring(now() - last_seen, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've included a fancy way of displaying a duration in days, hours, minutes, seconds and subseconds as well - see what you actually want and use that.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Oct 2014 22:48:01 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-10-17T22:48:01Z</dc:date>
    <item>
      <title>How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172804#M49559</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I might be over thinking this one, but since I've already used _time--&amp;gt; ...| stats earliest(_time) as first_seen, latest(_time) as last_seen, ... |, is it possible find the "current_time"?&lt;/P&gt;

&lt;P&gt;What I want to do is do something like ..| eval days_since=(current_time-last_seen)&lt;/P&gt;

&lt;P&gt;Is this possible?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:56:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172804#M49559</guid>
      <dc:creator>_gkollias</dc:creator>
      <dc:date>2020-09-28T17:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172805#M49560</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/174728"&gt;@_gkollias&lt;/a&gt;&lt;/P&gt;

&lt;P&gt;Are you looking for something like this?&lt;/P&gt;

&lt;P&gt;...| eval days_since=(now()-last_seen)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:54:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172805#M49560</guid>
      <dc:creator>ppablo</dc:creator>
      <dc:date>2020-09-28T17:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172806#M49561</link>
      <description>&lt;P&gt;There are two &lt;CODE&gt;eval&lt;/CODE&gt; functions for this, &lt;CODE&gt;now()&lt;/CODE&gt; and &lt;CODE&gt;time()&lt;/CODE&gt;. The major distinction is that &lt;CODE&gt;now()&lt;/CODE&gt; will be stable over a long-running search while &lt;CODE&gt;time()&lt;/CODE&gt; will yield a potentially new timestamp for every event/row/invocation... usually you'll want &lt;CODE&gt;now()&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats latest(_time) as last_seen | eval days_since = (now() - last_seen) / 86400 | eval duration_since = tostring(now() - last_seen, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've included a fancy way of displaying a duration in days, hours, minutes, seconds and subseconds as well - see what you actually want and use that.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Oct 2014 22:48:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172806#M49561</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-17T22:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172807#M49562</link>
      <description>&lt;P&gt;This is more towards what I am looking for!  Is there a way to measure by day(s)?  Here is a screenshot using your answer:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://screencast.com/t/9yVnvtpl" target="_blank"&gt;http://screencast.com/t/9yVnvtpl&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I'd like to be able to show something like "Today", 1 Day, or if greater than 1 , "x Days".  Here is what I was thinking using the case function:&lt;/P&gt;

&lt;P&gt;| eval days_since_last_txn=case(days_since_last_txn=0,"Today",days_since_last_txn=1,"1 Day",days_since_last_txn&amp;gt;1, days_since_last_txn."[".Days."]")  &lt;/P&gt;

&lt;P&gt;This didn't work for me, but do you have any insight on rounding by number of days?&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:56:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172807#M49562</guid>
      <dc:creator>_gkollias</dc:creator>
      <dc:date>2020-09-28T17:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172808#M49563</link>
      <description>&lt;P&gt;So... this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval days_since = floor((now() - last_seen) / 86400) | eval days_since_pretty = case(days_since == 0, "Today", days_since == 1, "1 Day", days_since &amp;gt; 1, days_since . " Days")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Oct 2014 00:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172808#M49563</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-18T00:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172809#M49564</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 18 Oct 2014 04:41:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172809#M49564</guid>
      <dc:creator>_gkollias</dc:creator>
      <dc:date>2014-10-18T04:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172810#M49565</link>
      <description>&lt;P&gt;Pipe  reltime to original query which created a field reltime to give time difference between now and _time in humar readable form.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Reltime"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Reltime&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2016 10:37:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/172810#M49565</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2016-07-18T10:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the time difference in days between the _time of an event and the current time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/603417#M209994</link>
      <description>&lt;P&gt;Thanks martin_mueller.&lt;/P&gt;&lt;P&gt;That also what I want.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2022 16:08:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-the-time-difference-in-days-between-the-time-of-an/m-p/603417#M209994</guid>
      <dc:creator>Rithekakan</dc:creator>
      <dc:date>2022-06-27T16:08:07Z</dc:date>
    </item>
  </channel>
</rss>

