<?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: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406929#M170918</link>
    <description>&lt;P&gt;What does work and what exactly does not work for you? Please be more specific, clearly describe what you have tried, what output you get, how that is different from what you expect.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2019 07:09:33 GMT</pubDate>
    <dc:creator>FrankVl</dc:creator>
    <dc:date>2019-06-05T07:09:33Z</dc:date>
    <item>
      <title>HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406925#M170914</link>
      <description>&lt;P&gt;hello&lt;BR /&gt;
I use the search below in order to calculate a last logon date and a last reboot date by host&lt;BR /&gt;
now I need to add 2 fields : the number of days since the last logon has occured and the number of days since the last reboot has occured&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" source="test" (EventCode=6005 OR EventCode=6006) 
| fields host SystemTime EventCode 
| eval SystemTime=strftime(strptime(SystemTime, "'%Y-%m-%dT%H:%M:%S.%9Q%Z'"), "%y-%m-%d %H:%M") 
| stats latest(SystemTime) as SystemTime by host EventCode 
| xyseries host EventCode SystemTime 
| rename "6005" as LastLogon "6006" as LastReboot 
| sort -LastLogon -LastReboot limit=10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried to do something like this but I dont succeed&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval NbDaysLogon= (now() - SystemTime) 
| eval NbDaysReboot= (now() - SystemTime) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;could you help me please?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 11:15:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406925#M170914</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-06-04T11:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406926#M170915</link>
      <description>&lt;P&gt;Hi @jip31,&lt;/P&gt;

&lt;P&gt;Reason your query is not working is:&lt;BR /&gt;
SystemTime is string and now() is integer. Earliert SystemTime was string then with strptime you converted it to integer. And with strftime you again converted to string. Remove outer strftime function, something like.&lt;BR /&gt;
&lt;CODE&gt;| eval SystemTime=strptime(SystemTime, "'%Y-%m-%dT%H:%M:%S.%9Q%Z'")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;To find NoOfDay you can use:&lt;BR /&gt;
&lt;CODE&gt;| eval NoDaysLogon = round((now() - SystemTime)/(3600*24), 2)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps!!!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 12:50:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406926#M170915</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-04T12:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406927#M170916</link>
      <description>&lt;P&gt;And to add to that:&lt;/P&gt;

&lt;P&gt;Doing &lt;CODE&gt;stats latest()&lt;/CODE&gt; after stripping off the _time field is also a bit tricky. Either do as below (incl. _time in the fields command).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="test" source="test" (EventCode=6005 OR EventCode=6006) 
 | fields _time host SystemTime EventCode 
 | eval SystemTime=strptime(SystemTime, "'%Y-%m-%dT%H:%M:%S.%9Q%Z'")
 | stats latest(SystemTime) as SystemTime by host EventCode 
 | xyseries host EventCode SystemTime 
 | rename "6005" as LastLogon "6006" as LastReboot 
 | sort -LastLogon -LastReboot limit=10
 | eval NbDaysLogon=round((now() - LastLogon)/(3600*24), 2)
 | eval NbDaysReboot=round((now() - LastReboot )/(3600*24), 2)
 | convert ctime(LastLogon) | convert ctime(LastReboot)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or do like this (taking the max value of SystemTime, rather than the latest):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="test" source="test" (EventCode=6005 OR EventCode=6006) 
 | fields host SystemTime EventCode 
 | eval SystemTime=strptime(SystemTime, "'%Y-%m-%dT%H:%M:%S.%9Q%Z'")
 | stats max(SystemTime) as SystemTime by host EventCode 
 | xyseries host EventCode SystemTime 
 | rename "6005" as LastLogon "6006" as LastReboot 
 | sort -LastLogon -LastReboot limit=10
 | eval NbDaysLogon=round((now() - LastLogon)/(3600*24), 2)
 | eval NbDaysReboot=round((now() - LastReboot )/(3600*24), 2)
 | convert ctime(LastLogon) | convert ctime(LastReboot)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In any case, as @VatsalJagani suggested, you need to keep SystemTime as a number during the calculations and only change it to a string later (I use the convert command for that at the very end in above examples).&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 13:15:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406927#M170916</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-06-04T13:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406928#M170917</link>
      <description>&lt;P&gt;thanks franck&lt;BR /&gt;
I dont succeed to display the data like this :&lt;/P&gt;

&lt;P&gt;| table host LastLogon LastReboot NbDaysReboot NbDaysReboot&lt;BR /&gt;
what I have to do please??&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 03:24:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406928#M170917</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-06-05T03:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406929#M170918</link>
      <description>&lt;P&gt;What does work and what exactly does not work for you? Please be more specific, clearly describe what you have tried, what output you get, how that is different from what you expect.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 07:09:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406929#M170918</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-06-05T07:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406930#M170919</link>
      <description>&lt;P&gt;franck&lt;BR /&gt;
after other checking the search globally works &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
just, I would like to change the LastLogon and LastReboot format&lt;BR /&gt;
I tried to change  | eval SystemTime but I have issues&lt;BR /&gt;
Actually the format is 06/04/2019 19:04:05.964162&lt;BR /&gt;
06/04/2019 19:04 format will be enough&lt;BR /&gt;
and last thing, I would like to have the fields in this order :&lt;BR /&gt;
host LastLogon NbDaysLogon Lastreboot NbDaysReboot&lt;BR /&gt;
Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 10:40:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406930#M170919</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-06-05T10:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406931#M170920</link>
      <description>&lt;P&gt;Changing the order of the fields should be possible by adding a table command at the very end of the search.&lt;/P&gt;

&lt;P&gt;Changing the time format can be done by either using &lt;CODE&gt;eval LastLogon=strftime(LastLogon, "%y-%m-%d %H:%M")&lt;/CODE&gt; instead of the convert command I used, or by changing the timeformat applied by the convert command: `convert timeformat= "%y-%m-%d %H:%M" ctime(LastLogon)&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 11:34:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406931#M170920</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-06-05T11:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: HELP ON EVAL FOR CALCULATING A NUMBER OF DAYS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406932#M170921</link>
      <description>&lt;P&gt;perfect thanks a lot&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 11:54:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/HELP-ON-EVAL-FOR-CALCULATING-A-NUMBER-OF-DAYS/m-p/406932#M170921</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-06-05T11:54:56Z</dc:date>
    </item>
  </channel>
</rss>

