Splunk Search

How to convert a string to date from my log file?

AyanC
New Member

My log file contains data in the below format. I need to sort the date by the latest one first. Please help as I am unable to convert the string to date format for sorting.

May  4 15:45    

I need to sort the data in latest to oldest format and the date format in the scene is like Jan 15

Please help!!

0 Karma

woodcock
Esteemed Legend

Like this:

... | eval Time=strptime(YourStringTimeFieldHere, "%b %d %H:%M") | sort 0 - Time

But the right thing to do, if this is your main timestamp is have Splunk use it for the main timestamp when you index your data. You should only need to do this if this field is some kind of "other" timestamp.

0 Karma

micahkemp
Champion

Is Splunk not parsing this out correctly at index time? Does your event timestamp not match the string time in the log?

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...