Splunk Search

How to convert a date string "d/mm/yyyy" that can be sorted in chronological order correctly?

HattrickNZ
Motivator

converting date string "d/mm/yyyy" into "d/mm/yyyy" that can be ordered correctly.

I have a column with a Date in string format "1/01/2011" (d/mm/yyyy), but when I sort this column by date it does not work as it is in a string format.

this is what I get:

1/01/2011
1/01/2012
1/01/2013
1/01/2014
1/01/2015
1/01/2016
1/02/2011
1/02/2012
1/02/2013
1/02/2014
1/02/2015
1/02/2016

Is there a way to do an eval on this column, or other way, and correct this?

This is what I want:

1/01/2011
2/01/2011
3/01/2011
4/01/2011
...

NOTE: I basically have a csv file that I am importing and this is the format it appears in splunk when it is imported.

Tags (3)
0 Karma
1 Solution

s2_splunk
Splunk Employee
Splunk Employee

Check this post, the accepted answer is one way to do that.

View solution in original post

the_wolverine
Champion

If the dates you are trying to sort are properly represented by _time you can sort by _time then eval after sorting:

your search | sort _time | eval Date=...

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

Check this post, the accepted answer is one way to do that.

HattrickNZ
Motivator

tks vm this is what done it for me

to help me understand whats going on:
... | eval Date2=strptime(Date, "%d/%m/%Y") | sort Date2 | eval Date3=strftime(Date2, "%d/%m/%Y")

the same as above but with out extra columns:
... | eval Date=strptime(Date, "%d/%m/%Y") | sort Date | eval Date=strftime(Date, "%d/%m/%Y")

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...