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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...