<?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: Custom Date Conversion and Parsing in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Custom-Date-Conversion-and-Parsing/m-p/195776#M56443</link>
    <description>&lt;P&gt;Your conversions require that you use the full specification of the timestamp;&lt;/P&gt;

&lt;P&gt;Tue, 31 Dec 2013 17:48:19 +0000&lt;/P&gt;

&lt;P&gt;First you need to convert it from string to &lt;CODE&gt;epoch&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval xxx = strptime(your_date_field,"%a, %d %b %Y %H:%M:%S %z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then you can convert it back into subparts with the &lt;CODE&gt;strftime&lt;/CODE&gt; function&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval yyy = strftime(xxx,"%d")
eval zzz = strftime(xxx,"%m-%d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the timestamp field you are using for these conversion is the same that is used by Splunk for indexing the event, you can skip the first step and use &lt;CODE&gt;_time&lt;/CODE&gt; instead. In this case, you may also have the desired subparts extracted in the various &lt;CODE&gt;date_*&lt;/CODE&gt; fields. Beware though, that these are not adjusted for timezone differences.&lt;/P&gt;

&lt;P&gt;see; &lt;/P&gt;

&lt;P&gt;&lt;A href="http://www.strftime.net"&gt;www.strftime.net&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
    <pubDate>Sat, 04 Jan 2014 10:37:37 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2014-01-04T10:37:37Z</dc:date>
    <item>
      <title>Custom Date Conversion and Parsing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Date-Conversion-and-Parsing/m-p/195774#M56441</link>
      <description>&lt;P&gt;We have a field in some of the JSON that that is a string representation of a date.  The date is formatted like this:&lt;/P&gt;

&lt;P&gt;Tue, 31 Dec 2013 17:48:19 +0000&lt;/P&gt;

&lt;P&gt;How can I convert this string into a date, so that we can parse various parts of the date out at search-time?  Currently it seems that we cannot convert it at all, and the resulting fieldname comes out blank.  Ex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | convert timeformat="%Y-%m-%d" ctime(OUR_DATE_FIELD) AS day | table OUR_DATE_FIELD, day
... | convert timeformat="%Y-%m" ctime(OUR_DATE_FIELD) AS month | table OUR_DATE_FIELD, month
... | eval day=strftime(OUR_DATE_FIELD, "%y-%m-%d") | table OUR_DATE_FIELD, day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, if we replace &lt;CODE&gt;OUR_DATE_FIELD&lt;/CODE&gt; with _time, it obviously resolves correctly.&lt;/P&gt;

&lt;P&gt;Inevitably I would like to be able to easily toggle between report types like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | convert timeformat="%Y-%m-%d" ctime(OUR_DATE_FIELD) AS day | timechart count by day
... | convert timeformat="%Y-%m" ctime(OUR_DATE_FIELD) AS month | timechart count by month
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jan 2014 02:32:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Date-Conversion-and-Parsing/m-p/195774#M56441</guid>
      <dc:creator>sheanineseven</dc:creator>
      <dc:date>2014-01-04T02:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Date Conversion and Parsing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Date-Conversion-and-Parsing/m-p/195775#M56442</link>
      <description>&lt;P&gt;For converting human-readable date strings into epoch time you can use &lt;CODE&gt;eval&lt;/CODE&gt;'s &lt;CODE&gt;strptime&lt;/CODE&gt; function. Its result can be used in &lt;CODE&gt;strftime&lt;/CODE&gt; to get whichever part of the date you need.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jan 2014 10:16:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Date-Conversion-and-Parsing/m-p/195775#M56442</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-04T10:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Date Conversion and Parsing</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Date-Conversion-and-Parsing/m-p/195776#M56443</link>
      <description>&lt;P&gt;Your conversions require that you use the full specification of the timestamp;&lt;/P&gt;

&lt;P&gt;Tue, 31 Dec 2013 17:48:19 +0000&lt;/P&gt;

&lt;P&gt;First you need to convert it from string to &lt;CODE&gt;epoch&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval xxx = strptime(your_date_field,"%a, %d %b %Y %H:%M:%S %z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then you can convert it back into subparts with the &lt;CODE&gt;strftime&lt;/CODE&gt; function&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval yyy = strftime(xxx,"%d")
eval zzz = strftime(xxx,"%m-%d")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the timestamp field you are using for these conversion is the same that is used by Splunk for indexing the event, you can skip the first step and use &lt;CODE&gt;_time&lt;/CODE&gt; instead. In this case, you may also have the desired subparts extracted in the various &lt;CODE&gt;date_*&lt;/CODE&gt; fields. Beware though, that these are not adjusted for timezone differences.&lt;/P&gt;

&lt;P&gt;see; &lt;/P&gt;

&lt;P&gt;&lt;A href="http://www.strftime.net"&gt;www.strftime.net&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.1/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jan 2014 10:37:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Date-Conversion-and-Parsing/m-p/195776#M56443</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-01-04T10:37:37Z</dc:date>
    </item>
  </channel>
</rss>

