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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...