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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...