<?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: DateTime Convertion in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321984#M96187</link>
    <description>&lt;P&gt;Not sure what is wrong based on IDateTime that you have in your screenshot. Can you try a different command for the same?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| convert timeformat="%m-%d-%Y %I:%M:%S %p" mktime(IDateTime)
| fieldformat IDateTime=strftime(date,"%m-%d-%Y %I:%M:%S %p")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Use of fieldformat instead of eval will keep underlying field as it is (in our case epochtime) and just display the changed value (human readable date).&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2017 06:40:28 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-02-22T06:40:28Z</dc:date>
    <item>
      <title>DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321982#M96185</link>
      <description>&lt;P&gt;Hi, I don't understand why my datetime extracted can't convert when same format has no issue&lt;/P&gt;

&lt;P&gt;host="gm*w8*" OR host="gm*w12*" sourcetype="WinEventLog:System" EventCode=6008&lt;BR /&gt;
|rex field=Message "at (?.&lt;EM&gt;[M])"&lt;BR /&gt;
|rex field=Message "on (?.&lt;/EM&gt;)/(?.&lt;EM&gt;)/(?[^ ]&lt;/EM&gt;)"&lt;BR /&gt;
|eval IDate=IMon+"-"+IDay+"-"+IYear&lt;BR /&gt;
|eval IDateTime= IDate+" "+ITime&lt;BR /&gt;
|eval IDateTime_epoch = strptime(IDateTime, "%m-%d-%Y %l:%M:%S %p")&lt;BR /&gt;
|eval DateTime = strftime(IDateTime_epoch, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
| eval my_time = "2-14-2017 1:06:59 PM"&lt;BR /&gt;
| eval my_time_epoch = strptime(my_time, "%m-%d-%Y %l:%M:%S %p")&lt;BR /&gt;
| eval mytime = strftime(my_time_epoch, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;
|table IDateTime,IDateTime_epoch,DateTime,my_time,my_time_epoch,mytime&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/186185-2017-02-21-16-47-45.jpg" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:00:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321982#M96185</guid>
      <dc:creator>duyanhtr</dc:creator>
      <dc:date>2020-09-29T13:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321983#M96186</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;It's possible that maybe you've picked up an extract character (space, newline, carriage return) in your &lt;CODE&gt;rex&lt;/CODE&gt; commands.&lt;/P&gt;

&lt;P&gt;The code in you're question for the &lt;CODE&gt;rex&lt;/CODE&gt; statements doesn't quite look complete, as it doesn't have any named capture groups. But I'm assuming that you're extracting IMon, IDay, IYear and ITime, as you use these later in your &lt;CODE&gt;eval&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;One thing you could try would be to check the length of your field IDateTime, to make sure that it is what you'd expect. Just &lt;CODE&gt;eval&lt;/CODE&gt; another field, such as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval IDateTime_Len=len(IDateTime)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not sure if that will be it, but it's worth a look.&lt;/P&gt;

&lt;P&gt;You could also check that each of the fields is being extracted as a String, so that you're concatenation works. Check these with the &lt;CODE&gt;typeof()&lt;/CODE&gt; function.&lt;/P&gt;

&lt;P&gt;The final one is try using the period (.) instead of the plus (+) for the concatenation. This one shouldn't make a difference, but it's what I'd normally do, just from a readability perspective, to know that I'm not trying to do addition on the fields.&lt;/P&gt;

&lt;P&gt;If you could also add some example data and the full &lt;CODE&gt;rex&lt;/CODE&gt; commands, there might be some pointers there too.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 03:38:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321983#M96186</guid>
      <dc:creator>gvmorley</dc:creator>
      <dc:date>2017-02-22T03:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321984#M96187</link>
      <description>&lt;P&gt;Not sure what is wrong based on IDateTime that you have in your screenshot. Can you try a different command for the same?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
| convert timeformat="%m-%d-%Y %I:%M:%S %p" mktime(IDateTime)
| fieldformat IDateTime=strftime(date,"%m-%d-%Y %I:%M:%S %p")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Use of fieldformat instead of eval will keep underlying field as it is (in our case epochtime) and just display the changed value (human readable date).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 06:40:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321984#M96187</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-02-22T06:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321985#M96188</link>
      <description>&lt;P&gt;thankyou for helping&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 22:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321985#M96188</guid>
      <dc:creator>duyanhtr</dc:creator>
      <dc:date>2017-02-23T22:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321986#M96189</link>
      <description>&lt;P&gt;i spent countless hours then find out my raw data has "invisible character" known as Left-to-right mark (\u200e)&lt;/P&gt;

&lt;P&gt;FML ... thankyou for suggesting look at the len.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 22:54:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321986#M96189</guid>
      <dc:creator>duyanhtr</dc:creator>
      <dc:date>2017-02-23T22:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321987#M96190</link>
      <description>&lt;P&gt;When you post a question, answer or comment, make sure to mark the code as code (that's the button with the 101 010 on it) so that the interface will not strip out your tags or anything in angle brackets &amp;lt; &amp;gt;.  &lt;/P&gt;

&lt;P&gt;It's especially important if you want feedback on your regexs.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 04:02:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321987#M96190</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-24T04:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321988#M96191</link>
      <description>&lt;P&gt;Glad that you solved your problem.  Please accept an answer so that everyone knows the problem was solved.  &lt;/P&gt;

&lt;P&gt;gvmorley's seems to have pointed you to the solution.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 04:11:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321988#M96191</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-24T04:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime Convertion</title>
      <link>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321989#M96192</link>
      <description>&lt;P&gt;@duyanhtr... Anytime, did mktime work for you despite the spooky character?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 16:53:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/DateTime-Convertion/m-p/321989#M96192</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-02-24T16:53:39Z</dc:date>
    </item>
  </channel>
</rss>

