<?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: How to transform a string to a date field? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218311#M42920</link>
    <description>&lt;P&gt;Why not just parse this at index time?&lt;/P&gt;

&lt;P&gt;Put this in your &lt;CODE&gt;props.conf&lt;/CODE&gt; on the indexer and you won't need to extract and tarnsform it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TIME_FORMAT=%Y%m%d/%H%M%S.%3N
 TIME_PREFEX=set as per your log
 MAX_TIMESTAMP_LOOKAHEAD=17
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 08 Aug 2016 16:52:15 GMT</pubDate>
    <dc:creator>skoelpin</dc:creator>
    <dc:date>2016-08-08T16:52:15Z</dc:date>
    <item>
      <title>How to transform a string to a date field?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218310#M42919</link>
      <description>&lt;P&gt;I have a regex which extracts a field with format &lt;CODE&gt;MMM DD YYYY HH24:MM:SS, SSS GMT TIMEZONEDIFF&lt;/CODE&gt; - e.g. &lt;CODE&gt;Aug 08 2016 10:85:49,444 GMT-0300*&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;Currently the extracted field is of String type. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;How can I use field transformation to convert it to a date format?&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;End objective is - if I use &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|table extractedDateField
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I should see the values in a Splunk date format.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 16:46:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218310#M42919</guid>
      <dc:creator>sarthakb</dc:creator>
      <dc:date>2016-08-08T16:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a string to a date field?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218311#M42920</link>
      <description>&lt;P&gt;Why not just parse this at index time?&lt;/P&gt;

&lt;P&gt;Put this in your &lt;CODE&gt;props.conf&lt;/CODE&gt; on the indexer and you won't need to extract and tarnsform it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TIME_FORMAT=%Y%m%d/%H%M%S.%3N
 TIME_PREFEX=set as per your log
 MAX_TIMESTAMP_LOOKAHEAD=17
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Aug 2016 16:52:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218311#M42920</guid>
      <dc:creator>skoelpin</dc:creator>
      <dc:date>2016-08-08T16:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a string to a date field?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218312#M42921</link>
      <description>&lt;P&gt;Does this field is same (or expected to be same) as your _time field? If yes then follow instructions from @skoelpin on setting _time value from this field. &lt;BR /&gt;
If not (means this is another date time field available in your events and you just want to convert it to epoch format), then you'd need to create a calculated field using the strptime function. See this for more details&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.4.2/Knowledge/definecalcfields"&gt;https://docs.splunk.com/Documentation/Splunk/6.4.2/Knowledge/definecalcfields&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The eval expression that you can use will be like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EVAL-extractedDateField = strptime(extractedDateField,"%b %d %Y %H:%M:%S,%N %Z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this if above doesn't work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EVAL-extractedDateField = strptime(replace(extractedDateField,"^((\S+\s){4})([^-\+]+)(-|\+)(\d+)","\1\3") ,"%b %d %Y %H:%M:%S,%N %Z")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Aug 2016 17:18:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218312#M42921</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-08-08T17:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a string to a date field?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218313#M42922</link>
      <description>&lt;P&gt;BTW, your example date is wrong (min is 85). An actual sample would be better.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 17:20:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218313#M42922</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-08-08T17:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a string to a date field?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218314#M42923</link>
      <description>&lt;P&gt;Every way, to transform your string in a date in epochtime you have to eztract a field with your date and then tranform it using eval&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval newfield=strptime(yourfield,"%m %d %Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want it in another format instead epochtime use strftime.&lt;BR /&gt;
Bye.&lt;BR /&gt;
Giuseppe &lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 17:28:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218314#M42923</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2016-08-08T17:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a string to a date field?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218315#M42924</link>
      <description>&lt;P&gt;try this,&lt;/P&gt;

&lt;P&gt;The expected token for convert your string is &lt;CODE&gt;%b %d %Y %H:%M:%S,%N GMT%z&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|stats c | eval c1="Aug 08 2016 10:25:49,444 GMT-0300" | eval c2=strptime(c1,"%b %d %Y %H:%M:%S,%N GMT%z") | eval c3=strftime(c2,"%+")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;c1 : String / Extracted field&lt;BR /&gt;
c2: Converted in Unix time (epoch) &lt;BR /&gt;
c3: epoch to human readable format. &lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 17:33:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218315#M42924</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2016-08-08T17:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a string to a date field?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218316#M42925</link>
      <description>&lt;P&gt;Thanks for your comment. i will try out both the options.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 17:53:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-transform-a-string-to-a-date-field/m-p/218316#M42925</guid>
      <dc:creator>sarthakb</dc:creator>
      <dc:date>2016-08-08T17:53:34Z</dc:date>
    </item>
  </channel>
</rss>

