<?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 convert string date format to other date format? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358560#M166512</link>
    <description>&lt;P&gt;And a fourth answer using a different method (only the &lt;CODE&gt;rex&lt;/CODE&gt; command is really the answer part):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval date="08Aug2017 10:12:55 CDT"
| rex field=date mode=sed "s/(\d\d)(\w{3})(\d{4})/\1-\2-\3/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One reason Splunk is great is that there are so many ways to do something. I thought it would be good to provide multiple ways here because we can all learn from what others do. I think that all the previous answers are all good and worthy of looking at. Mine is very simple, relying only on a single &lt;CODE&gt;rex&lt;/CODE&gt; command, but if you need something more complicated that what it will do, I think that woodcock's and cmerriman's answers can give you the most flexibility if you need to go with a format that differs more than you have described. I'm up-voting those answers.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2017 16:18:24 GMT</pubDate>
    <dc:creator>cpetterborg</dc:creator>
    <dc:date>2017-08-08T16:18:24Z</dc:date>
    <item>
      <title>How to convert string date format to other date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358556#M166508</link>
      <description>&lt;P&gt;I have string like this 08Aug2017 10:12:55 CDT"&lt;/P&gt;

&lt;P&gt;I want date format like = 08-Aug-2017 10:12:55 CDT&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 07:29:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358556#M166508</guid>
      <dc:creator>prabu116</dc:creator>
      <dc:date>2017-08-08T07:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string date format to other date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358557#M166509</link>
      <description>&lt;P&gt;@prabu116, you can use &lt;CODE&gt;replace()&lt;/CODE&gt; function with &lt;CODE&gt;eval&lt;/CODE&gt; command. Following is run anywhere search, you can use your own base search and field name&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval date="08Aug2017 10:12:55 CDT"
| eval date=replace(date,"^(\d{2})(\w{3})","\1-\2-")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Aug 2017 11:44:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358557#M166509</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-08T11:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string date format to other date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358558#M166510</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval date=strftime(strptime(dateField,"%d%b%Y %H:%M:%S %Z"),"%d-%b-%Y %H:%M:%S %Z")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;it will basically put your string into epoch time and then put it back as a date string in the format you want. &lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 11:45:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358558#M166510</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-08-08T11:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string date format to other date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358559#M166511</link>
      <description>&lt;P&gt;The &lt;EM&gt;right&lt;/EM&gt; way to do it is to convert to &lt;CODE&gt;time_t&lt;/CODE&gt; (AKA "epoch") and KEEP it that way.  Then use &lt;CODE&gt;fieldformat&lt;/CODE&gt; to make it look pretty:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval MyDate=strptime(MyDate,"%d%b%Y %H:%M:%S %Z")
| fieldformat MyDate = strftime(MyDate, "%d-%b-%Y %H:%M:%S %Z")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Aug 2017 14:34:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358559#M166511</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-08T14:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string date format to other date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358560#M166512</link>
      <description>&lt;P&gt;And a fourth answer using a different method (only the &lt;CODE&gt;rex&lt;/CODE&gt; command is really the answer part):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval date="08Aug2017 10:12:55 CDT"
| rex field=date mode=sed "s/(\d\d)(\w{3})(\d{4})/\1-\2-\3/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One reason Splunk is great is that there are so many ways to do something. I thought it would be good to provide multiple ways here because we can all learn from what others do. I think that all the previous answers are all good and worthy of looking at. Mine is very simple, relying only on a single &lt;CODE&gt;rex&lt;/CODE&gt; command, but if you need something more complicated that what it will do, I think that woodcock's and cmerriman's answers can give you the most flexibility if you need to go with a format that differs more than you have described. I'm up-voting those answers.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 16:18:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358560#M166512</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-08-08T16:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string date format to other date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358561#M166513</link>
      <description>&lt;P&gt;This is work fine. Thanks a lot niletnilay&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 12:32:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358561#M166513</guid>
      <dc:creator>prabu116</dc:creator>
      <dc:date>2017-08-09T12:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert string date format to other date format?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358562#M166514</link>
      <description>&lt;P&gt;Glad it worked. You got plenty of options to choose from &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 15:56:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-string-date-format-to-other-date-format/m-p/358562#M166514</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-09T15:56:09Z</dc:date>
    </item>
  </channel>
</rss>

