Splunk Search

sort by Time desc

shangshin
Builder

Hi, I tried to format the eventtime and would like to show the latest time event first. However, the search string below always displays the oldest event first, What's even weird is that when I clicked on the Time header in the table, the column is still not sorted. I am wondering if anyone can shed some light on this? Thank you!

| bucket _time span=60m | eval Time=strftime(_time, "%m/%d %H:%M %Z") | STATS avg(time_taken) AS AverageResponseTime BY Time | sort by Time desc

Tags (2)
1 Solution

Ayn
Legend

Your syntax is a little off. Have a look at sort's syntax here: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

This should work better:

... | sort - Time

View solution in original post

gblock_splunk
Splunk Employee
Splunk Employee

If you are trying to sort by the extracted timestamp, then _time is what you want to use i.e.

| sort -_time

I just hit this and it was driving me nuts as I was using Time and not seeing the expected result.

Ayn
Legend

Your syntax is a little off. Have a look at sort's syntax here: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Sort

This should work better:

... | sort - Time

evanriegel
New Member

Hi there, this answer isn't working for me. Here's the query I'm typing:

name@email.com | sort - Time

And in the output I'm seeing:

Time
5/2/19 7:38:41.000 PM
5/2/19 7:38:44.769 PM
5/2/19 7:38:44.000 PM

So, not only is the order not descending, but it's not even sorted. Splunk is ignoring my sort directive altogether and is just doing whatever it wants instead.

Please advise?
Thanks

0 Karma

shangshin
Builder

Thank you.

0 Karma

dmorozov
New Member

Hello, it doesn't seems to work for me 😞
The source type is log4j logs. Splunk (light) successfully parsed date/time and shows me separate column in search results with name "Time". I tried (with space and without space after minus):
| sort -Time
| sort -_time

Whatever I do it just ignore and sort results ascending.
I figured out that if I put wrong field name it does the same. The name "_time" I tried to use because when you click on the value in Time column it shows option to show events before or auto and tell me that the field name is "_time". Could you make any suggestion please?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...