Splunk Search

Find the duration between two events

luna
Explorer

Hello,

I need to find the duration between two events. I went over the solutions on Splunk, but still can't get the calculation. Both sentToSave and SaveDoc have the time stamp already formatted that is why I used the case function. I am able to see the fields populate with their time stamps, but I am not able to get the Duration field to populate the duration - it simply does not populate at all. Need some help on how to get the Duration - any advise? Below is my query

(index=souce1 dept=qvc  event="sentToSave"  ) OR (index=source dept=save area=saveDoc)

 

| eval saveDocTime=case(area="saveDoc", TimeStamp),

sentToSaveTime=case(event="sentToSave", TimeStamp)

| eval Duration=saveDocTime-sentToSaveTime

| stats values(Duration) as Duration earliest(sentToSaveTime) as sentToSaveTime latest(saveDocTime) as saveDocTime  by emailRequest

| where isNotNull(sentToSaveTime) AND isNotNull(saveDocTime)

 

Labels (2)
0 Karma

luna
Explorer

I also needed to have turned the times I was subtracting to epoch. I used strptime to subtract the times then I was able to get duration.

0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @luna,

Since saveDocTime and sentToSaveTime fields are not in the same event, Duration cannot be calculated. Please try below;

(index=souce1 dept=qvc event="sentToSave" ) OR (index=source dept=save area=saveDoc) 
| eval saveDocTime=case(area="saveDoc", TimeStamp), sentToSaveTime=case(event="sentToSave", TimeStamp) 
| stats earliest(sentToSaveTime) as sentToSaveTime latest(saveDocTime) as saveDocTime by emailRequest 
| eval Duration=saveDocTime-sentToSaveTime 
| where isNotNull(sentToSaveTime) AND isNotNull(saveDocTime)
If this reply helps you an upvote and "Accept as Solution" is appreciated.
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...