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!

.conf24 | Day 0

Hello Splunk Community! My name is Chris, and I'm based in Canberra, Australia's capital, and I travelled for ...

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...