Getting Data In

How do I convert the date format in a custom field?

egt
New Member

Hi,

I'm new here. I want to convert the format from "Thu Jan 31 23:01:13 CET 2019" to "31 Jan 2019" in a custom date field.

How can I do that?

0 Karma
1 Solution

Vijeta
Influencer

@egt If your time is in say variable x, then you need to use strptime to convert in time in seconds and then use strftime to convert it to format you need

eval y=strptime(x,"%a %b %d %H:%M:%S %Z %Y")|eval z= strftime(y,"%d %b %Y")

See the example created using makeresults.

|makeresults|eval x= "Thu Jan 31 23:01:13 CET 2019"| eval y=strptime(x,"%a %b %d %H:%M:%S %Z %Y")|eval z= strftime(y,"%d %b %Y")

View solution in original post

0 Karma

Vijeta
Influencer

@egt If your time is in say variable x, then you need to use strptime to convert in time in seconds and then use strftime to convert it to format you need

eval y=strptime(x,"%a %b %d %H:%M:%S %Z %Y")|eval z= strftime(y,"%d %b %Y")

See the example created using makeresults.

|makeresults|eval x= "Thu Jan 31 23:01:13 CET 2019"| eval y=strptime(x,"%a %b %d %H:%M:%S %Z %Y")|eval z= strftime(y,"%d %b %Y")
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this query:

... | eval time = strftime(strptime(existingTimeField, "%a %b %d %H:%M:%S %Z %Y"), "%d %b %Y") | ...
---
If this reply helps you, Karma would be appreciated.
0 Karma

vnravikumar
Champion

Hi @egt

Try like

| makeresults 
| eval date="Thu Jan 31 23:01:13 CET 2019" 
| eval epoch = strptime(date,"%a %b %d %H:%M:%S %Z %Y") 
| eval new_date =strftime(epoch,"%d %b %Y")
0 Karma

PowerPacked
Builder

Hi

Try this

| eval new_time = strftime(yourtimefield, "%d %b %Y")

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...