Splunk Search

Compare timestamps

ericrobinson
Path Finder

Is it possible to compare two times and get the difference in seconds? I have a field I am extracting called rec_time that I would like to compare to the timestamp on the event. This will show us the delay of processing the message. Both timestamps are in 24H time ..:..:..

Thanks!

Tags (1)
0 Karma

Stephen_Sorkin
Splunk Employee
Splunk Employee

The timestamp of the event is already available in epoch seconds in the field called _time. The next step is to convert rec_time to an epoch seconds using the eval command and strptime. Let's assume that it's formatted as: 2010-08-25T19:55:01-0700. Your search would be:

... | eval diff = _time - strptime(rec_time, "%Y-%m-%dT%H:%M:%S%z")
0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...