Splunk Search

Why is time formatting not working with my search?

jaho_splunk
Engager

Why is time formatting not working with the following search:

index=_internal sourcetype=splunkd  "Ignoring" AND "binary" | eval time=strftime(_time, "%m/%d/%y %H:%M:%S") | stats earliest(_time) as start, latest(_time) as stop by message, host
0 Karma
1 Solution

somesoni2
Revered Legend

The field name created for formatted _time is not used in stats, hence the problem. Try like this

index=_internal sourcetype=splunkd  "Ignoring" AND "binary" | eval time=strftime(_time, "%m/%d/%y %H:%M:%S") | stats earliest(time) as start, latest(time) as stop by message, host

OR more efficient method (formatting should be done after aggregation, if possible/feasible)

 index=_internal sourcetype=splunkd  "Ignoring" AND "binary" | stats earliest(_time) as start, latest(_time) as stop by message, host | convert ctime(start) ctime(stop) timeformat="%m/%d/%y %H:%M:%S"

View solution in original post

somesoni2
Revered Legend

The field name created for formatted _time is not used in stats, hence the problem. Try like this

index=_internal sourcetype=splunkd  "Ignoring" AND "binary" | eval time=strftime(_time, "%m/%d/%y %H:%M:%S") | stats earliest(time) as start, latest(time) as stop by message, host

OR more efficient method (formatting should be done after aggregation, if possible/feasible)

 index=_internal sourcetype=splunkd  "Ignoring" AND "binary" | stats earliest(_time) as start, latest(_time) as stop by message, host | convert ctime(start) ctime(stop) timeformat="%m/%d/%y %H:%M:%S"

jaho_splunk
Engager

Thank you somesoni2 for the solution.

0 Karma

ppablo
Retired

Hi @jaho_splunk

If somesoni2's answer solved your question, please don't forget to resolve the post by clicking "Accept" directly below his answer and upvote him for being helpful. Thanks!

Get Updates on the Splunk Community!

Splunk Enterprise Security(ES) 7.3 is approaching the end of support. Get ready for ...

Hi friends!    At Splunk, your product success is our top priority. With Enterprise Security (ES), we're here ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...