Splunk Search

How to convert Aug-16 which is in text to a date format such that I can sort?

ravitejaj
Explorer

For example I have the below data as text:

Aug-16
Sep-16
Oct-16
Nov-16
Feb-16

When I sort it with Month, I wish to see:

Feb-16
Aug-16
Sep-16
Oct-16
Nov-16

Currently When I sort, it shows as

Aug-16
Feb-16
Nov-16
Oct-16
Sep-16

Tags (2)
0 Karma

gokadroid
Motivator

Try this I am assuming your date is coming in a field myField

yourQuery to return myField
| eval newTime="00:00:00 01-".myField
| eval monthYear=strptime(newTime,"%H:%M:%S %d-%b-%y") 
| fieldformat monthYear=strftime(monthYear, "%b-%y")
| table myField, monthYear 
| sort monthYear

Try to replace last line | sort monthYear with | sort myField and see the difference.

0 Karma

HiroshiSatoh
Champion

How about converting for sorting?

・・・|eval sort_field=strptime(text_date,"%b-%d")|sort sort_field|fields - sort_field

0 Karma

ravitejaj
Explorer

Hey Horishi,

This is not working.. First of all strptime is not returning any data.

eval text_date="Aug-16" | eval sort_field=strptime(text_date,"%b-%d")|sort sort_field|fields - sort_field | table sort_field

0 Karma

HiroshiSatoh
Champion

I am deleting the sort_field .

|fields - sort_field | table sort_field

| table sort_field

0 Karma

ravitejaj
Explorer

Still the Sort is not working..

0 Karma

ravitejaj
Explorer

eval a=strftime(strptime(Approval_Month,"%b-%d"), "%b-%y") | table a | sort a

0 Karma

HiroshiSatoh
Champion

I mistook the day and the year.

eval a=strftime(strptime(Approval_Month,"%b-%d"), "%b-%y") | table a | sort a

eval wk_Approval_Month="00:00:00:01-"+Approval_Month|eval a=strftime(strptime(wk_Approval_Month,"%H:%M:%S:%d-%b-%y"),"%Y-%m") | sort a

※a=2016-08

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...