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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...