<?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 help on eval command for calculating the difference between now() and a date field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380359#M170475</link>
    <description>&lt;P&gt;hi &lt;BR /&gt;
I use the search below&lt;BR /&gt;
"LAST_SEEN" is a field with a date format like "2019-06-07 09:12:40.0"&lt;BR /&gt;
I need to add an eval command in the search in order to be calculate the events which are older than a month&lt;BR /&gt;
So I need to do something like eval delta =(now() - LAST_SEEN) because after I want to add a where command in order to be able to display the events &amp;lt; one month&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x sourcetype=wireless
    [| inputlookup host.csv 
    | table host 
    | rename host as USERNAME ] | stats latest(LAST_SEEN) by USERNAME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Could you help me please&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 01:15:07 GMT</pubDate>
    <dc:creator>jip31</dc:creator>
    <dc:date>2020-09-30T01:15:07Z</dc:date>
    <item>
      <title>help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380359#M170475</link>
      <description>&lt;P&gt;hi &lt;BR /&gt;
I use the search below&lt;BR /&gt;
"LAST_SEEN" is a field with a date format like "2019-06-07 09:12:40.0"&lt;BR /&gt;
I need to add an eval command in the search in order to be calculate the events which are older than a month&lt;BR /&gt;
So I need to do something like eval delta =(now() - LAST_SEEN) because after I want to add a where command in order to be able to display the events &amp;lt; one month&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x sourcetype=wireless
    [| inputlookup host.csv 
    | table host 
    | rename host as USERNAME ] | stats latest(LAST_SEEN) by USERNAME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Could you help me please&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:15:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380359#M170475</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2020-09-30T01:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380360#M170476</link>
      <description>&lt;P&gt;Use &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/DateandTimeFunctions"&gt;strptime()&lt;/A&gt; to convert LAST_SEEN into a UNIX timestamp.&lt;/P&gt;

&lt;P&gt;Check this out. This will get all events which are less than 30 days old:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval LAST_SEEN="2019-06-07 09:12:40.0"
| eval LAST_SEEN_EPOCH=strptime(LAST_SEEN, "%Y-%m-%d %H:%M:%S.%1N")
| eval diff_seconds=now()-LAST_SEEN_EPOCH
| where diff_seconds&amp;lt;60*60*24*30
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Jul 2019 15:29:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380360#M170476</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2019-07-07T15:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380361#M170477</link>
      <description>&lt;P&gt;hi&lt;BR /&gt;
I done this&lt;BR /&gt;
    index=x sourcetype=wireless_client_val &lt;BR /&gt;
    | eval LAST_SEEN_EPOCH=strptime(LAST_SEEN, "%Y-%m-%d %H:%M:%S.%1N") &lt;BR /&gt;
    | eval diff_seconds=now()-LAST_SEEN_EPOCH &lt;BR /&gt;
    | where diff_seconds&amp;lt;(60*60*24*30)&lt;BR /&gt;
        [| inputlookup host.csv &lt;BR /&gt;
        | table host &lt;BR /&gt;
        | rename host as USERNAME ] &lt;BR /&gt;
    | lookup lookup_cmdb_fo_all.csv HOSTNAME as USERNAME output SITE &lt;BR /&gt;
    | search SITE="*" &lt;BR /&gt;
    | stats values(SITE) as SITE, latest(LAST_SEEN_EPOCH) by USERNAME&lt;/P&gt;

&lt;P&gt;But I have 2 issues :&lt;BR /&gt;
1)  Error in 'where' command: The operator at is invalid&lt;BR /&gt;
2) Error in 'eval' command: The 'last_seen_epoch' function is unsupported or undefined.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:15:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380361#M170477</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2020-09-30T01:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380362#M170478</link>
      <description>&lt;P&gt;"[| inputlookup host.csv ..." is a subsearch. It requires the "search" command. Try it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| where diff_seconds&amp;lt;(60*60*24*30)
| search [inputlookup host.csv |table host | rename host as USERNAME ]
| lookup ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I removed the pipe symbol | at the beginning of the subsearch. It is not necessary.&lt;/P&gt;

&lt;P&gt;In your original post, the subsearch belonged to the initial search. (When you write index=x it translates to | search index=x.) That is why there was no error before.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 08:10:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380362#M170478</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2019-07-08T08:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380363#M170479</link>
      <description>&lt;P&gt;does it seems correct now?&lt;BR /&gt;
LAST_SEEN_EPOCH result has to be a number of days&lt;BR /&gt;
actually its 1562572180.000000 format&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=X sourcetype=wireless_client_val 
| eval LAST_SEEN_EPOCH=strptime(LAST_SEEN, "%Y-%m-%d %H:%M:%S.%1N") 
| eval diff_seconds=now()-LAST_SEEN_EPOCH 
| where diff_seconds&amp;lt;(60*60*24*30) 
| search 
    [ inputlookup host.csv 
    | table host 
    | rename host as USERNAME ] 
| lookup lookup_cmdb_fo_all.csv HOSTNAME as USERNAME output SITE 
| search SITE="*" 
| stats values(SITE) as SITE, latest(LAST_SEEN_EPOCH) by USERNAME
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:15:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380363#M170479</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2020-09-30T01:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380364#M170480</link>
      <description>&lt;P&gt;Looks fine to me.&lt;BR /&gt;
If you want the number of days, then try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval age_in_days=floor((now()-LAST_SEEN_EPOCH)/60/60/24)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jul 2019 09:01:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380364#M170480</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2019-07-08T09:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380365#M170481</link>
      <description>&lt;P&gt;So I have done :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=x sourcetype=wireless_client_val 
| eval LAST_SEEN_DAYS=strptime(LAST_SEEN, "%Y-%m-%d %H:%M:%S.%1N") 
| eval LAST_SEEN_DAYS=floor((now()-LAST_SEEN_DAYS)/60/60/24) 
| where LAST_SEEN_DAYS&amp;gt;2 
| search 
    [ inputlookup host.csv 
    | table host 
    | rename host as USERNAME] 
| lookup lookup_cmdb_fo_all.csv HOSTNAME as USERNAME output SITE 
| search SITE=*
| stats values(SITE) as SITE, latest(LAST_SEEN_DAYS) as LAST_SEEN_DAYS by USERNAME 
| sort -LAST_SEEN_DAYS
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jul 2019 10:06:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380365#M170481</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-07-08T10:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380366#M170482</link>
      <description>&lt;P&gt;But I have questions&lt;BR /&gt;
1) Could you please explain me /60/60/24?&lt;BR /&gt;
2) Is it possible to have the number of days with a decimal?&lt;BR /&gt;
2) Are you sure that the formatting works fine because when I execute the request I have a last seen value of 13 days and when I look the events directly I see that the last seen is 3 days&lt;BR /&gt;
Normally latest(LAST_SEEN_EPOCH) by USERNAME catch well the last events? So why I have 13 days instead 3 days??&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:15:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380366#M170482</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2020-09-30T01:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380367#M170483</link>
      <description>&lt;P&gt;1) now() and LAST_SEEN_EPOCH are unix time stamp, which is measured in seconds since Jan 01 1970. So now()-LAST_SEEN_DAYS gives you the time difference in seconds. Now /60 gives you the difference in minutes; /60/60 is the difference in hours; and /60/60/24 is the difference in days.&lt;BR /&gt;
2) Use round((now()-LAST_SEEN_EPOCH)/60/60/24, 2)&lt;BR /&gt;
3) Try max(LAST_SEEN_DAYS) instead of latest(LAST_SEEN_DAYS)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:15:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380367#M170483</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2020-09-30T01:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: help on eval command for calculating the difference between now() and a date field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380368#M170484</link>
      <description>&lt;P&gt;thanks for your help!&lt;BR /&gt;
MAX dont work anymore but I m going to open a specific topic on this&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 11:24:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/help-on-eval-command-for-calculating-the-difference-between-now/m-p/380368#M170484</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-07-08T11:24:09Z</dc:date>
    </item>
  </channel>
</rss>

