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!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...