Knowledge Management

Time difference between 2 fields

nathanluke86
Communicator

How can I get the time difference between two fields below

alt text

TIA

0 Karma
1 Solution

skoelpin
SplunkTrust
SplunkTrust

Like this.. This will convert your fields to epoch time, find the difference, then convert to hours/min/sec

| eval time_epoch=strptime(time, "%m/%d/%y %H:%M:%S")
| eval timenow_epoch=strptime(timenow, "%m/%d/%y %H:%M:%S")
| eval diff=timenow_epoch-time_epoch
| eval diff=strftime(diff, "%H:%M:%S")

View solution in original post

manjunathmeti
Champion

Use:

| eval time_diff = strptime(timenow, "%m/%d/%y %H:%M:%S") - strptime(time, "%m/%d/%y %H:%M:%S")

Sample query:

| makeresults | eval time="02/18/20 12:00:45",  timenow="02/18/20 14:12:32" | eval time_diff = strptime(timenow, "%m/%d/%y %H:%M:%S") - strptime(time, "%m/%d/%y %H:%M:%S")

nathanluke86
Communicator

Thanks @manjunathmeti

0 Karma

skoelpin
SplunkTrust
SplunkTrust

Like this.. This will convert your fields to epoch time, find the difference, then convert to hours/min/sec

| eval time_epoch=strptime(time, "%m/%d/%y %H:%M:%S")
| eval timenow_epoch=strptime(timenow, "%m/%d/%y %H:%M:%S")
| eval diff=timenow_epoch-time_epoch
| eval diff=strftime(diff, "%H:%M:%S")

nathanluke86
Communicator

Thankyou @skoelpin

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 ...