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?
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")
This works, but does not seem to sort as a date
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")