<?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 sort a string time format to show the latest time? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374060#M160516</link>
    <description>&lt;P&gt;When I run my search for a month back I still see May before June.&lt;/P&gt;

&lt;P&gt;sourcetype=aaaaaaa | eval sortDate=strptime(Date,"%b %d %H:%M:%S %Y") |sort sortDate|fields - sortDate| table Date, ID, COMMAND &lt;/P&gt;</description>
    <pubDate>Wed, 28 Jun 2017 21:24:11 GMT</pubDate>
    <dc:creator>ewise1</dc:creator>
    <dc:date>2017-06-28T21:24:11Z</dc:date>
    <item>
      <title>How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374056#M160512</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a string date format that shows up when I do a search; what I did was did a field extraction and named that string as Date, and create a table and sort -Date to show the latest date, but apparently it doesn't work since it acts as a text. Please advice. Date formats are as below:&lt;/P&gt;

&lt;P&gt;May 31 22:06:20 2017&lt;BR /&gt;
May 29 22:06:20 2017&lt;BR /&gt;
June 28 22:06:20 2017&lt;BR /&gt;
June 27 22:06:20 2017&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 20:58:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374056#M160512</guid>
      <dc:creator>ewise1</dc:creator>
      <dc:date>2017-06-28T20:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374057#M160513</link>
      <description>&lt;P&gt;You're right, Splunk is performing a lexicographical sort on your dates.  To sort them in date order, use a hidden epoch timestamp.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval sortDate=strptime(Date,"%b %d %H:%M:%S %Y") | sort sortDate | fields - sortDate
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:10:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374057#M160513</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-06-28T21:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374058#M160514</link>
      <description>&lt;P&gt;For a more detailed proof that Rich is right:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="May 31 22:06:20 2017,
May 29 22:06:20 2017,
June 28 22:06:20 2017,
June 27 22:06:20 2017" | makemv raw delim="," | mvexpand raw 
| eval sortbytime=strptime(raw, "%b %d %H:%M:%S %Y") 
| sort sortbytime | fields - sortbytime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The dates are in the right order as you can see.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:13:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374058#M160514</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-06-28T21:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374059#M160515</link>
      <description>&lt;P&gt;++&lt;BR /&gt;
Only suggestion is that requester wants latest date first so you'd need &lt;CODE&gt;| sort -sortDate&lt;/CODE&gt; .&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:17:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374059#M160515</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-06-28T21:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374060#M160516</link>
      <description>&lt;P&gt;When I run my search for a month back I still see May before June.&lt;/P&gt;

&lt;P&gt;sourcetype=aaaaaaa | eval sortDate=strptime(Date,"%b %d %H:%M:%S %Y") |sort sortDate|fields - sortDate| table Date, ID, COMMAND &lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:24:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374060#M160516</guid>
      <dc:creator>ewise1</dc:creator>
      <dc:date>2017-06-28T21:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374061#M160517</link>
      <description>&lt;P&gt;Slightly different version than @richgalloway. For sorting you either need epochtime (number of ticks) or else string time in YYYY/MM/DD HH:MM:SS format so that older date are smaller event with string comparison. &lt;/P&gt;

&lt;P&gt;However, since you string time is not in above format, you would anyways need to first convert to epochTime. So 2nd approach is beating around the bush. The following approach lets you sort based on epoch time however, it does not create an additional field since the same epoch time is formatted as string time only for displaying in table.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... 
| eval Date=strptime(Date,"%b %d %H:%M:%S %Y") 
| sort Date 
| fieldformat Date=strftime(Date,"%b %d %H:%M:%S %Y") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374061#M160517</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-06-28T21:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374062#M160518</link>
      <description>&lt;P&gt;As somesoni2 suggests, try &lt;CODE&gt;| sort - sortDate |&lt;/CODE&gt; to reverse the display order.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 21:29:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374062#M160518</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-06-28T21:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374063#M160519</link>
      <description>&lt;P&gt;Great Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 22:23:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374063#M160519</guid>
      <dc:creator>ewise1</dc:creator>
      <dc:date>2017-06-28T22:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374064#M160520</link>
      <description>&lt;P&gt;Thanks alot for the hint &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 22:23:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374064#M160520</guid>
      <dc:creator>ewise1</dc:creator>
      <dc:date>2017-06-28T22:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374065#M160521</link>
      <description>&lt;P&gt;Thanks for your comment &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 22:24:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374065#M160521</guid>
      <dc:creator>ewise1</dc:creator>
      <dc:date>2017-06-28T22:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a string time format to show the latest time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374066#M160522</link>
      <description>&lt;P&gt;Did it work?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 17:19:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-string-time-format-to-show-the-latest-time/m-p/374066#M160522</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-06-29T17:19:17Z</dc:date>
    </item>
  </channel>
</rss>

