Splunk Search

time command

shreyasamin64
Explorer

need help on using command strptime/strftime

 

EX: input: December 7, 2021 1:00:01 PM 

        output: 12/1/2021   13:00:01 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| eval output=strftime(strptime(input,"%B %d, %Y %I:%M:%S %p"),"%m/%d/%Y %H:%M:%S")

View solution in original post

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

I didn't found formatter where day was without leading space so if this is really what you are wanting, you could try this.

 

| makeresults
| eval time1 = "December 7, 2021 1:00:01 PM"
| eval time2 = strptime(time1, "%B %e, %Y %I:%M:%S %p")
| eval time3 = strftime(time2, "%m/%e/%Y %H:%M:%S")
| rex field=time3 mode=sed "s,/\s(\d+)/,/\1/,g"
| table time1 time3

 

If you can accept leading zero then just change later %e -> %d and forget rex.

r. Ismo

 https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval output=strftime(strptime(input,"%B %d, %Y %I:%M:%S %p"),"%m/%d/%Y %H:%M:%S")
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...