Splunk Search

How to convert a String date format to another date format?

ewise1
New Member

Hi,

I have a date that comes in as part of a string, and it looks like "Jun 28 11:50:23 2017". How can I convert this to show "Jun 28 2017 11:50:23"?

Tags (1)
0 Karma
1 Solution

niketn
Legend

Try the following run anywhere search

| makeresults 
| eval Time="Jun 28 11:50:23 2017"
| eval Time=strptime(Time, "%b %d %H:%M:%S %Y")
| fieldformat Time=strftime(Time,"%b %d %Y %H:%M:%S")

PS: final fieldformat command is just displaying epoch time field Time to human readable string time as per your need. You might have to use eval instead of fieldformat is you want to use String Time down the line in your Splunk Search rather than epoch time.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@cpetterborg, thanks for reminding of sed, following replace should also do the trick

 | makeresults 
 | eval Time="Jun 28 11:50:23 2017"
 | eval Time=replace(Time,"(\w{3}\s\d{2})(\s\d{2}:\d{2}:\d{2})(\s\d{4})","\1\3\2")

Basically June 28 is extracted as 1st Capturing group 11:50:23 as 2nd and 2017 as 3rd. Then replace is used to format them in correct sequence i.e. 1, 3, 2. Output field will remain String Date. Refer to the documentation: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#Basic_example_4

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

cpetterborg
SplunkTrust
SplunkTrust

This will also work in your case, without using as much processing:

 | makeresults 
 | eval Time="Jun 28 11:50:23 2017"
 | rex field=Time mode=sed "s/(\w+\s\d+)\s(\d+:\d+:\d+)\s(\d+)/\\1 \\3 \\2/"

niketn
Legend

Try the following run anywhere search

| makeresults 
| eval Time="Jun 28 11:50:23 2017"
| eval Time=strptime(Time, "%b %d %H:%M:%S %Y")
| fieldformat Time=strftime(Time,"%b %d %Y %H:%M:%S")

PS: final fieldformat command is just displaying epoch time field Time to human readable string time as per your need. You might have to use eval instead of fieldformat is you want to use String Time down the line in your Splunk Search rather than epoch time.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...