<?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 sort a time field in a 12hr time format (AM/PM)? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215630#M63202</link>
    <description>&lt;P&gt;How do I sort a column of time in 12 hour format with AM / PM on the end?  I have tried using eval with the &lt;STRONG&gt;_time&lt;/STRONG&gt; field (which gives a standard output like:  &lt;CODE&gt;2016-01-13 13:23:38&lt;/CODE&gt; and my sourcetype is a standard Windows Security Event Log.  &lt;/P&gt;

&lt;P&gt;The following syntax displays a column called TIME, with the time displayed in 24hr format.  I don't need to sort it as it's sorted automatically from earliest to latest.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval TIME = strftime(_time, "%H:%M:%S")
... | table TIME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, when changing the time to 12hr format (%I instead of %H) and the trailing AM /PM ( by adding %p), the auto-sort ignores the AM/PM and uses the values as numbers, not 'time-aware' values so to say. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval TIME = strftime(_time, "%I:%M:%S %p")
... | table TIME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can the earliest to latest sort be achieved using 12hr time?  &lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2016 06:33:25 GMT</pubDate>
    <dc:creator>SQservicedesk</dc:creator>
    <dc:date>2016-02-23T06:33:25Z</dc:date>
    <item>
      <title>How to sort a time field in a 12hr time format (AM/PM)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215630#M63202</link>
      <description>&lt;P&gt;How do I sort a column of time in 12 hour format with AM / PM on the end?  I have tried using eval with the &lt;STRONG&gt;_time&lt;/STRONG&gt; field (which gives a standard output like:  &lt;CODE&gt;2016-01-13 13:23:38&lt;/CODE&gt; and my sourcetype is a standard Windows Security Event Log.  &lt;/P&gt;

&lt;P&gt;The following syntax displays a column called TIME, with the time displayed in 24hr format.  I don't need to sort it as it's sorted automatically from earliest to latest.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval TIME = strftime(_time, "%H:%M:%S")
... | table TIME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, when changing the time to 12hr format (%I instead of %H) and the trailing AM /PM ( by adding %p), the auto-sort ignores the AM/PM and uses the values as numbers, not 'time-aware' values so to say. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval TIME = strftime(_time, "%I:%M:%S %p")
... | table TIME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can the earliest to latest sort be achieved using 12hr time?  &lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 06:33:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215630#M63202</guid>
      <dc:creator>SQservicedesk</dc:creator>
      <dc:date>2016-02-23T06:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a time field in a 12hr time format (AM/PM)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215631#M63203</link>
      <description>&lt;P&gt;You can use fieldformat:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| fieldformat _time=strftime(_time,"%I:%M:%S %p")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2016 09:49:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215631#M63203</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-23T09:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a time field in a 12hr time format (AM/PM)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215632#M63204</link>
      <description>&lt;P&gt;I would suggest to sort first (using TIME) and then change the format.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 18:16:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215632#M63204</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-02-23T18:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a time field in a 12hr time format (AM/PM)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215633#M63205</link>
      <description>&lt;P&gt;Thanks javiergn, but I have tried using fieldformat already.  It shows the exact same result as eval - it shows the information, but does not sort it correctly.&lt;/P&gt;

&lt;P&gt;Example, if I use: &lt;/P&gt;

&lt;P&gt;| fieldformat _time=strftime(_time,"%I:%M:%S %p")&lt;BR /&gt;
 | table _time&lt;BR /&gt;
 | sort _time &lt;/P&gt;

&lt;P&gt;The results are close, but still not correct: &lt;/P&gt;

&lt;P&gt;07:57:50 AM&lt;BR /&gt;&lt;BR /&gt;
07:58:20 AM&lt;BR /&gt;&lt;BR /&gt;
09:52:06 AM&lt;BR /&gt;&lt;BR /&gt;
09:52:34 AM&lt;BR /&gt;&lt;BR /&gt;
08:09:17 AM&lt;BR /&gt;&lt;BR /&gt;
08:09:20 AM&lt;BR /&gt;&lt;BR /&gt;
08:09:35 AM&lt;BR /&gt;&lt;BR /&gt;
11:42:41 AM&lt;BR /&gt;&lt;BR /&gt;
11:43:07 AM&lt;BR /&gt;&lt;BR /&gt;
04:02:13 PM&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:57:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215633#M63205</guid>
      <dc:creator>SQservicedesk</dc:creator>
      <dc:date>2020-09-29T08:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort a time field in a 12hr time format (AM/PM)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215634#M63206</link>
      <description>&lt;P&gt;Thanks - I tried this but received the same result.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 02:08:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-a-time-field-in-a-12hr-time-format-AM-PM/m-p/215634#M63206</guid>
      <dc:creator>SQservicedesk</dc:creator>
      <dc:date>2016-02-24T02:08:07Z</dc:date>
    </item>
  </channel>
</rss>

