<?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 a String date format to another date format? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373933#M160523</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a date that comes in as part of a string, and it looks like "Jun 28 11:50:23 2017". How can I convert this to show "Jun 28 2017 11:50:23"?&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jun 2017 20:08:38 GMT</pubDate>
    <dc:creator>ewise1</dc:creator>
    <dc:date>2017-06-28T20:08:38Z</dc:date>
    <item>
      <title>How to convert a String date format to another date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373933#M160523</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a date that comes in as part of a string, and it looks like "Jun 28 11:50:23 2017". How can I convert this to show "Jun 28 2017 11:50:23"?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 20:08:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373933#M160523</guid>
      <dc:creator>ewise1</dc:creator>
      <dc:date>2017-06-28T20:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a String date format to another date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373934#M160524</link>
      <description>&lt;P&gt;Try the following run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval Time="Jun 28 11:50:23 2017"
| eval Time=strptime(Time, "%b %d %H:%M:%S %Y")
| fieldformat Time=strftime(Time,"%b %d %Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: final fieldformat command is just displaying epoch time field &lt;STRONG&gt;Time&lt;/STRONG&gt; to human readable string time as per your need. You might have to use eval instead of fieldformat is you want to use String Time down the line in your Splunk Search rather than epoch time.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 20:43:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373934#M160524</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-06-28T20:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a String date format to another date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373935#M160525</link>
      <description>&lt;P&gt;This will also work in your case, without using as much processing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults 
 | eval Time="Jun 28 11:50:23 2017"
 | rex field=Time mode=sed "s/(\w+\s\d+)\s(\d+:\d+:\d+)\s(\d+)/\\1 \\3 \\2/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:06:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373935#M160525</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-06-28T21:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a String date format to another date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373936#M160526</link>
      <description>&lt;P&gt;@cpetterborg, thanks for reminding of sed, following &lt;STRONG&gt;replace&lt;/STRONG&gt; should also do the trick&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults 
 | eval Time="Jun 28 11:50:23 2017"
 | eval Time=replace(Time,"(\w{3}\s\d{2})(\s\d{2}:\d{2}:\d{2})(\s\d{4})","\1\3\2")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically June 28 is extracted as 1st Capturing group 11:50:23 as 2nd and 2017 as 3rd. Then replace is used to format them in correct sequence i.e. 1, 3, 2. Output field will remain String Date. Refer to the documentation: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#Basic_example_4"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#Basic_example_4&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:35:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-a-String-date-format-to-another-date-format/m-p/373936#M160526</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-06-28T21:35:55Z</dc:date>
    </item>
  </channel>
</rss>

