<?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 Sort 12-hour based date/time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118464#M31610</link>
    <description>&lt;P&gt;I have a dashboard table based on the search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=eaccess Card_Name="John*" 
| convert timeformat="%m/%d/%y %I:%M:%S %p" ctime(_time) as Date/Time 
| table Date/Time, Location | sort -Date/Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The Date/Time field displays correctly but when clicking on the header to sort, the AM/PM part of the date/time is not taken into account, e.g.: 01:59:29 PM comes before 06:45:15 AM which comes before 12:58:10 PM.&lt;/P&gt;

&lt;P&gt;If the sort command not able to handle 12-hour time format?&lt;/P&gt;

&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2013 17:12:57 GMT</pubDate>
    <dc:creator>lmarcel</dc:creator>
    <dc:date>2013-10-28T17:12:57Z</dc:date>
    <item>
      <title>Sort 12-hour based date/time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118464#M31610</link>
      <description>&lt;P&gt;I have a dashboard table based on the search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=eaccess Card_Name="John*" 
| convert timeformat="%m/%d/%y %I:%M:%S %p" ctime(_time) as Date/Time 
| table Date/Time, Location | sort -Date/Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The Date/Time field displays correctly but when clicking on the header to sort, the AM/PM part of the date/time is not taken into account, e.g.: 01:59:29 PM comes before 06:45:15 AM which comes before 12:58:10 PM.&lt;/P&gt;

&lt;P&gt;If the sort command not able to handle 12-hour time format?&lt;/P&gt;

&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2013 17:12:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118464#M31610</guid>
      <dc:creator>lmarcel</dc:creator>
      <dc:date>2013-10-28T17:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sort 12-hour based date/time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118465#M31611</link>
      <description>&lt;P&gt;It's not as much that it's not able to handle it as that it has no idea that the string you're asking it to sort is a timestamp. When you convert() &lt;CODE&gt;_time&lt;/CODE&gt; to Date/Time, you will get a string that happens to represent a time in a text format, but any sort command you will throw at it just knows that it's some kind of text that it's supposed to sort. It's better to use &lt;CODE&gt;fieldformat&lt;/CODE&gt; so you can represent the data the way you want but still be able to sort it.&lt;/P&gt;

&lt;P&gt;By the way you don't need to sort this because Splunk will already grab the most recent events first.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=eaccess Card_Name="John*" 
| fieldformat _time=strftime(_time,"%m/%d/%y %I:%M:%S %p")
| table _time, Location
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Oct 2013 17:40:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118465#M31611</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-10-28T17:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sort 12-hour based date/time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118466#M31612</link>
      <description>&lt;P&gt;Thank you very much, I didn't realize that the output of convert() was a string. It's working now. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2013 17:53:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118466#M31612</guid>
      <dc:creator>lmarcel</dc:creator>
      <dc:date>2013-10-28T17:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sort 12-hour based date/time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118467#M31613</link>
      <description>&lt;P&gt;For the sake of completion, here is what I ended up using:&lt;/P&gt;

&lt;P&gt;index=eaccess Card_Name="John*"&lt;BR /&gt;
    | rename _time as Date/Time&lt;BR /&gt;
    | fieldformat Date/Time = strftime('Date/Time',"%m/%d/%y %I:%M:%S %p")&lt;BR /&gt;
    | table Date/Time, Location&lt;BR /&gt;
    | sort Date/Time&lt;/P&gt;

&lt;P&gt;If the sort command is left out, clicking on the table header won't change the sorting order.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2013 18:52:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-12-hour-based-date-time/m-p/118467#M31613</guid>
      <dc:creator>lmarcel</dc:creator>
      <dc:date>2013-10-28T18:52:29Z</dc:date>
    </item>
  </channel>
</rss>

