Splunk Search

Date sorting

ND
Path Finder

Hi,

 

I have below data:

Date:

Sep 2020

Aug 2018

Feb 2020

July 2017

Sep 2019

I want to sort the date by month and year

Like July 2017

Aug 2018

Sep 2019

Feb 2020

Sep 2020

 

 

I am using eval strftime function but ouput is coming as

Sep 2020 

Sep 2019

Can someone please help me to fix this.

 

Thanks!!

Labels (1)
Tags (4)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

How exactly are you using the strptime function?

Sorting dates accurately into chronological order requires that they be converted into integer form.  Otherwise, the dates are sorted lexicographically.

... | eval sortby = strptime (Date, "%b %Y")
| sort + sortby
| fields - sortby
| table ...
---
If this reply helps you, Karma would be appreciated.
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You need to parse the dates with strptime to get the equivalent epoch dates - this is a number. When you sort by this number the dates will be in the right order. You then convert them back to string format using strftime. If you do that with fieldformat, you don't change then value of the epoch date field, you just change how it is displayed. This may give you what you want.

0 Karma
Get Updates on the Splunk Community!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...