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

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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...