<?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: Date conversion needed in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582385#M202846</link>
    <description>&lt;P&gt;Replace Age_Days with...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;eval Age_Days=ceiling((now()-strptime(Last_Checkin,"%Y-%m-%dT%H:%M:%SZ"))/86400)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;You are specifying %3N in your format string, which deals with a millisecond component.&amp;nbsp; Your time value in Last_Checkin doesn't have a millisecond component.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jan 2022 09:54:06 GMT</pubDate>
    <dc:creator>tread_splunk</dc:creator>
    <dc:date>2022-01-25T09:54:06Z</dc:date>
    <item>
      <title>Date conversion needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582346#M202835</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to calculate age for a task. Time is in below format. What am I missing?&lt;/P&gt;&lt;P&gt;| makeresults&lt;/P&gt;&lt;P&gt;| eval Last_Checkin="&lt;STRONG&gt;2021-05-26T20:47:22Z&lt;/STRONG&gt;"&lt;/P&gt;&lt;P&gt;| table Last_Checkin, _time&lt;/P&gt;&lt;P&gt;| eval Age_Days=ceiling((now()-strptime(Last_Checkin,"%Y-%m-%dT%H:%M:%S%3NZ"))/86400)&lt;BR /&gt;&lt;BR /&gt;| eval CVE_Age=case(&lt;/P&gt;&lt;P&gt;Age_Days&amp;lt;30,"A_0 to 29 Days",&lt;/P&gt;&lt;P&gt;Age_Days&amp;gt;=365,"G_365 Days+",&lt;/P&gt;&lt;P&gt;Age_Days&amp;gt;=180,"F_180 to 364 Days",&lt;/P&gt;&lt;P&gt;Age_Days&amp;gt;=120,"E_120 to 179 Days",&lt;/P&gt;&lt;P&gt;Age_Days&amp;gt;=90,"D_90 to 119 Days",&lt;/P&gt;&lt;P&gt;Age_Days&amp;gt;=60,"C_60 to 89 Days",&lt;/P&gt;&lt;P&gt;Age_Days&amp;gt;=30,"B_30 to 59 Days",&lt;/P&gt;&lt;P&gt;0==0,"H_No Age Data")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 02:45:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582346#M202835</guid>
      <dc:creator>mbasharat</dc:creator>
      <dc:date>2022-01-25T02:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582353#M202837</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/86891"&gt;@mbasharat&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you could try something like below&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval Last_Checkin="2021-05-26T20:47:22Z" 
| table Last_Checkin, _time 
| eval epoch=strptime(Last_Checkin, "%Y-%m-%dT%H:%M:%S") 
| eval diff_days=ceiling((_time-epoch)/86400)&lt;/LI-CODE&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;appreciate a vote if it helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 05:04:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582353#M202837</guid>
      <dc:creator>venkatasri</dc:creator>
      <dc:date>2022-01-25T05:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582370#M202841</link>
      <description>&lt;P&gt;Your example timestamp doesn't have 3 digits for the milliseconds, whereas your parse string for strptime specifies 3 digits, so the timestamp does not parse, hence the failure to determine what the epoch time is.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 09:56:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582370#M202841</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-25T09:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582375#M202842</link>
      <description>&lt;P&gt;One additional remark. I know that your example uses makeresults to produce a single result but if you eventually run your search on a production data you'll probably get several resulting events.&lt;/P&gt;&lt;P&gt;In that case you shouldn't use table command to limit the processed fields, but either leave the events alone or use fields command. At first glance&lt;/P&gt;&lt;PRE&gt;| table _time&lt;/PRE&gt;&lt;P&gt;seems to work the same as&lt;/P&gt;&lt;PRE&gt;| fields _time&lt;BR /&gt;| fields - _raw&lt;/PRE&gt;&lt;P&gt;But there is a huge difference. The table command is a transforming command and produces a statistical table whereas fields command works in a pipeline one event at a time.&lt;/P&gt;&lt;P&gt;So table is ok if you need to produce a nice looking table at the end of your processing pipeline but if you want to just limit your search to a subset of fields, do it with fields command.&lt;/P&gt;&lt;P&gt;For comparison - on my home splunk searching over 3.5 millions events with | fields took 58 seconds. If I switched to | table I stopped the search after few minutes and it only returned some 500k results. I think the difference would be even bigger in a distributed environment.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 08:29:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582375#M202842</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-01-25T08:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582385#M202846</link>
      <description>&lt;P&gt;Replace Age_Days with...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;eval Age_Days=ceiling((now()-strptime(Last_Checkin,"%Y-%m-%dT%H:%M:%SZ"))/86400)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;You are specifying %3N in your format string, which deals with a millisecond component.&amp;nbsp; Your time value in Last_Checkin doesn't have a millisecond component.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 09:54:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582385#M202846</guid>
      <dc:creator>tread_splunk</dc:creator>
      <dc:date>2022-01-25T09:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion needed</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582393#M202847</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@ PickleRick,&lt;/P&gt;&lt;P&gt;Yes, for real searches, I use fields &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 13:23:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Date-conversion-needed/m-p/582393#M202847</guid>
      <dc:creator>mbasharat</dc:creator>
      <dc:date>2022-01-25T13:23:51Z</dc:date>
    </item>
  </channel>
</rss>

