Getting Data In

How to turn string into date format?

vishalduttauk
Communicator

I have a string of data and i've created regex to break down that set into different fields. There are date values within it (start_date and end_date) but format is ddmmyyy i.e. 2901012001.How can i convert it into DD-MM-YYYY so Splunk recognises it as a date or can be shown in that date format?

Ideally i'd like that to be down on ingestion. I have a props.conf and transforms.conf file for the app this sits in

Labels (2)
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @vishalduttauk,

this means the the original format is "ddmmyyyy" (with 4 digits for the year), can you confirm?

in this case you can use my eval statement:

| your_date=strftime(strptime(yourfield,"%d%m%Y"),"%d-%m-%Y")

Ciao.

giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @vishalduttauk,

sorry, it isn't clear what's your fields format: you said "ddmmyyy"  but the sample you used has 10 digits (2901012001), what's the correct one?

Anyway, you have to convert it in epochtime and then in the date format you like, something like this:

| your_date=strftime(strptime(yourfield,"%d%m%Y"),"%d-%m-%Y")

Ciao.

Giuseppe 

0 Karma

vishalduttauk
Communicator

Hi @gcusello 

 

Thanks for your reply and sorry i pasted in the wrong information as an example but you are correct my message didn't have the correct format. it should have been 01021999.

 

Kind Regards,


Vishal

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @vishalduttauk,

this means the the original format is "ddmmyyyy" (with 4 digits for the year), can you confirm?

in this case you can use my eval statement:

| your_date=strftime(strptime(yourfield,"%d%m%Y"),"%d-%m-%Y")

Ciao.

giuseppe

vishalduttauk
Communicator

Thanks @gcusello 

Its the first time i am using eval so it worked after i put in | eval

👍

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...