<?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 How to Convert string to date field for field extraction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Convert-string-to-date-field-for-field-extraction/m-p/365458#M107777</link>
    <description>&lt;P&gt;I have a python program that's generating logs with the following format START_DATE=08-AUG-2017&lt;/P&gt;

&lt;P&gt;the problem is Splunk is interpreting the field value as a string and not a number, thus not a date. I would like to create a permanent field extraction to query the field as a date.  How do I do that? &lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2017 14:25:11 GMT</pubDate>
    <dc:creator>AJNZAZ</dc:creator>
    <dc:date>2017-08-10T14:25:11Z</dc:date>
    <item>
      <title>How to Convert string to date field for field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Convert-string-to-date-field-for-field-extraction/m-p/365458#M107777</link>
      <description>&lt;P&gt;I have a python program that's generating logs with the following format START_DATE=08-AUG-2017&lt;/P&gt;

&lt;P&gt;the problem is Splunk is interpreting the field value as a string and not a number, thus not a date. I would like to create a permanent field extraction to query the field as a date.  How do I do that? &lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 14:25:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Convert-string-to-date-field-for-field-extraction/m-p/365458#M107777</guid>
      <dc:creator>AJNZAZ</dc:creator>
      <dc:date>2017-08-10T14:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Convert string to date field for field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Convert-string-to-date-field-for-field-extraction/m-p/365459#M107778</link>
      <description>&lt;P&gt;This documentation speaks to the convert command:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Convert" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Convert&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Example: index="indexname" sourcetype="Sourcetype" Search condition | convert auto(Date) | stats count by Date&lt;/P&gt;

&lt;P&gt;If that does not help look at the strptime() function:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Commontimeformatvariables" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/CommonEvalFunctions" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/6.0/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Example: index="indexname" sourcetype="Sourcetype" Search condition | eval date_time = strptime(Date, "%H:%M") | stats count by date_time&lt;/P&gt;

&lt;P&gt;IF the issue your facing is with rex, look at the second link abo e for pattern options.  Before you get into testing the strptime, you should confirm that your rex works.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:19:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Convert-string-to-date-field-for-field-extraction/m-p/365459#M107778</guid>
      <dc:creator>mhouse3</dc:creator>
      <dc:date>2020-09-29T15:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Convert string to date field for field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Convert-string-to-date-field-for-field-extraction/m-p/365460#M107779</link>
      <description>&lt;P&gt;At extract time, that is on this page - &lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/6.6.1/Data/Configuretimestamprecognition"&gt;https://docs.splunk.com/Documentation/SplunkCloud/6.6.1/Data/Configuretimestamprecognition&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The entries would look something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your source type or source or whatever]
TIME_PREFIX =  START_DATE=
TIME_FORMAT = %d-%b-%Y
TZ = whatever time zone your data is coming from
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And if you also want the value stored as an epoch date in the START_DATE field as well, you could have a transform to do that... discussed here - &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.0/Data/Configureindex-timefieldextraction"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.0/Data/Configureindex-timefieldextraction&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;That might look something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[&amp;lt;unique_transform_stanza_name&amp;gt;]
REGEX = .
FORMAT = START_DATE::$1
DEST_KEY = START_DATE
SOURCE_KEY = _time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Aug 2017 16:13:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Convert-string-to-date-field-for-field-extraction/m-p/365460#M107779</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-10T16:13:15Z</dc:date>
    </item>
  </channel>
</rss>

