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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

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 GA in US-AWS!

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