Splunk Search

Reformat Date represented by string

atornes
Path Finder

One of the fields of my data is a date, represented as a string like 20120215. I need to reformat this date to m/d/y. How can I do this?

0 Karma
1 Solution

Ayn
Legend

Use eval with a combination of strptime and strftime to convert your string to a date in epoch format and then convert it back to the format you want it in:

... | eval reformatted_date=strftime(strptime(original_datefield,"%Y%m%d"),"%m/%d/%y")

View solution in original post

jaxjohnny
Path Finder

This works, but does not seem to sort as a date

0 Karma

Ayn
Legend

Use eval with a combination of strptime and strftime to convert your string to a date in epoch format and then convert it back to the format you want it in:

... | eval reformatted_date=strftime(strptime(original_datefield,"%Y%m%d"),"%m/%d/%y")
Get Updates on the Splunk Community!

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 ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...