<?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: Issue with time format calculation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421649#M121086</link>
    <description>&lt;P&gt;@jip31 the &lt;CODE&gt;NbDaysLogon&lt;/CODE&gt; and &lt;CODE&gt;NbDaysReboot&lt;/CODE&gt; logic seems to work fine. Have you verified that &lt;CODE&gt;SystemTime&lt;/CODE&gt; is converting to correct Epoch time? What is the SystemTime value when you pull it from index and display in a table (without any formatting)?&lt;/P&gt;

&lt;P&gt;Following is run anywhere example which generates Random Logon and Reboot days. Commands till &lt;CODE&gt;| table Today LastLogon LastReboot&lt;/CODE&gt; generate dummy data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=5 
| fields - _time 
| eval randomDiffLogon=random(),
       randomDiffReboot=random() 
| eval randomDiffLogon="-".substr(randomDiffLogon,1,2)."d@d",
       randomDiffReboot="-".substr(randomDiffReboot,1,2)."d@d"
       | map search="| makeresults
| fields - _time
| eval LastLogon=relative_time(now(),\"$randomDiffLogon$\"),
       LastReboot=relative_time(now(),\"$randomDiffReboot$\")"
| eval Today=now()
| fieldformat Today=strftime(Today,"%y-%m-%d %H:%M")
| table Today LastLogon LastReboot

| eval NbDaysLogon=round((now() - LastLogon)/(3600*24), 2) 
| eval NbDaysReboot=round((now() - LastReboot )/(3600*24), 2) 
| eval LastLogon=strftime(LastLogon, "%y-%m-%d %H:%M") 
| eval LastReboot=strftime(LastReboot, "%y-%m-%d %H:%M")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 16 Jun 2019 03:51:33 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-06-16T03:51:33Z</dc:date>
    <item>
      <title>Issue with time format calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421645#M121082</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
The request below is working but I have an issue on the NbDaysLogon and NbDaysReboot calculation.&lt;BR /&gt;
As you can see, the fields are the difference between now() and the systemtime of the event&lt;BR /&gt;
But there is a mistake somewhere because for example;&lt;BR /&gt;
&lt;EM&gt;If the systemtime is 19/05/2019 and assuming that now is today 13/062019 I have a result of 29 days instead 25 days.&lt;/EM&gt;&lt;BR /&gt;
What is the problem?&lt;BR /&gt;
Thank you.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="X" sourcetype=XmlWinEventLog source="XmlWinEventLog:System" (EventCode=6005 OR EventCode=6006) 
    | 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 
    | eval NbDaysLogon=round((now() - LastLogon)/(3600*24), 2) 
    | eval NbDaysReboot=round((now() - LastReboot )/(3600*24), 2) 
    | eval LastLogon=strftime(LastLogon, "%y-%m-%d %H:%M") 
    | eval LastReboot=strftime(LastReboot, "%y-%m-%d %H:%M") 
    | search NbDaysLogon$tok_logon$ 
    | search NbDaysReboot$tok_reboot$ 
    | lookup lookup_cmdb_fo_all.csv HOSTNAME as host output SITE COUNTRY TOWN ROOM 
    | where SITE=$SITE$ 
    | stats values(LastReboot) as LastReboot values(NbDaysReboot) as NbDaysReboot values(LastLogon) as LastLogon values(NbDaysLogon) as NbDaysLogon  values(COUNTRY) as COUNTRY values(TOWN) as TOWN values(SITE) as SITE values(ROOM) as ROOM by host 
    | sort -NbDaysLogon -NbDaysReboot limit=10
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Jun 2019 12:27:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421645#M121082</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-06-13T12:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with time format calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421646#M121083</link>
      <description>&lt;P&gt;The expressions looks good. Do all the NbDaysLogon values are off? Try to run half the search and verify if the values as you're expect.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 15:40:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421646#M121083</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-06-13T15:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with time format calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421647#M121084</link>
      <description>&lt;P&gt;Can you provide a sample event time for the 2019-05-19 data?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 18:09:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421647#M121084</guid>
      <dc:creator>jnudell_2</dc:creator>
      <dc:date>2019-06-13T18:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with time format calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421648#M121085</link>
      <description>&lt;P&gt;Hummm sorry I wonder if it's not me who cheated on me because I have inverted the date format (english to french) I continue my investigations and i keep you aware&lt;BR /&gt;
sorry&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 05:34:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421648#M121085</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-06-14T05:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with time format calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421649#M121086</link>
      <description>&lt;P&gt;@jip31 the &lt;CODE&gt;NbDaysLogon&lt;/CODE&gt; and &lt;CODE&gt;NbDaysReboot&lt;/CODE&gt; logic seems to work fine. Have you verified that &lt;CODE&gt;SystemTime&lt;/CODE&gt; is converting to correct Epoch time? What is the SystemTime value when you pull it from index and display in a table (without any formatting)?&lt;/P&gt;

&lt;P&gt;Following is run anywhere example which generates Random Logon and Reboot days. Commands till &lt;CODE&gt;| table Today LastLogon LastReboot&lt;/CODE&gt; generate dummy data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=5 
| fields - _time 
| eval randomDiffLogon=random(),
       randomDiffReboot=random() 
| eval randomDiffLogon="-".substr(randomDiffLogon,1,2)."d@d",
       randomDiffReboot="-".substr(randomDiffReboot,1,2)."d@d"
       | map search="| makeresults
| fields - _time
| eval LastLogon=relative_time(now(),\"$randomDiffLogon$\"),
       LastReboot=relative_time(now(),\"$randomDiffReboot$\")"
| eval Today=now()
| fieldformat Today=strftime(Today,"%y-%m-%d %H:%M")
| table Today LastLogon LastReboot

| eval NbDaysLogon=round((now() - LastLogon)/(3600*24), 2) 
| eval NbDaysReboot=round((now() - LastReboot )/(3600*24), 2) 
| eval LastLogon=strftime(LastLogon, "%y-%m-%d %H:%M") 
| eval LastReboot=strftime(LastReboot, "%y-%m-%d %H:%M")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Jun 2019 03:51:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421649#M121086</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-06-16T03:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with time format calculation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421650#M121087</link>
      <description>&lt;P&gt;Thanks to you!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 07:00:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Issue-with-time-format-calculation/m-p/421650#M121087</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2019-06-20T07:00:57Z</dc:date>
    </item>
  </channel>
</rss>

