Splunk Search

How to convert this numeric field to a date format? "20150223" to "2015-02-23"

isedrof
Engager

Hi everybody,

I need your help please, i want to convert a numeric field to a date.
Ex: "20150223" >> "2015-02-23"

Thank you.

Tags (3)
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Following are different ways

1) Using eval command

...| eval ProperDate=replace(tostring(NumericDate),"(\d{4})(\d{2})(\d{2})","\1-\2-\3" )
...| eval ProperDate=strftime(strptime(NumericDate,"%Y%m%d"),"%Y-%m-%d"))

2) Using rex command (overwrite the same field)

...| rex field=NumericDate mode=sed "s/(\d{4})(\d{2})(\d{2})/\1-\2-\3/g"

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Following are different ways

1) Using eval command

...| eval ProperDate=replace(tostring(NumericDate),"(\d{4})(\d{2})(\d{2})","\1-\2-\3" )
...| eval ProperDate=strftime(strptime(NumericDate,"%Y%m%d"),"%Y-%m-%d"))

2) Using rex command (overwrite the same field)

...| rex field=NumericDate mode=sed "s/(\d{4})(\d{2})(\d{2})/\1-\2-\3/g"

isedrof
Engager

Thank you guys, i tried the solution of @somesoni2 and it workes nicely.
Thanks again.

0 Karma

frobinson_splun
Splunk Employee
Splunk Employee

Hi @isedrof,
Have you tried the "convert" command to convert the numeric fields to dates? Here is some documentation for the command and for date and time variables:
http://docs.splunk.com/Documentation/Splunk/6.2.5/SearchReference/Convert
http://docs.splunk.com/Documentation/Splunk/6.2.5/SearchReference/Commontimeformatvariables

Hope this helps!
All best,
@frobinson_splunk

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...