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!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...