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!

Now Available: Cisco Talos Threat Intelligence Integrations for Splunk Security Cloud ...

At .conf24, we shared that we were in the process of integrating Cisco Talos threat intelligence into Splunk ...

Preparing your Splunk Environment for OpenSSL3

The Splunk platform will transition to OpenSSL version 3 in a future release. Actions are required to prepare ...

Easily Improve Agent Saturation with the Splunk Add-on for OpenTelemetry Collector

Agent Saturation What and Whys In application performance monitoring, saturation is defined as the total load ...