Splunk Search

How to generate a search that finds the time difference?

sravankaripe
Communicator

i want to find the difference b/w starttime and _time.

"StartTime":"2017-02-03 09:51:54.595" (String)
EndTime:2017-02-03 09:46:21,892

Please help me with Splunk search

0 Karma

aaraneta_splunk
Splunk Employee
Splunk Employee

@sravankaripe: Looks like you have a few possible solutions to your question. If one of them provided a working solution, please don't forget to click "Accept" below the best answer to resolve this post. If you still need help, please leave a comment. Don’t forget to upvote anything that was helpful too. Thank you.

0 Karma

somesoni2
Revered Legend

Try like this for difference between starttime (assuming field name is StartTime) and _time (Splunk extracted event timestamp)

your base search | eval Difference=_time -strptime(StartTime, "%Y-%m-%d %H:%M:%S.%3Q") | Diff_DurationFormat=tostring(Difference,"duration")
0 Karma

Richfez
SplunkTrust
SplunkTrust

IF those are already being shown as fields StartTime and EndTime, then this should work. NOTE is EndTime really differently formatted with a comma and not a period? Not really a problem, just double-check things.

base search ... | eval ConvertedStart=strptime(StartTime, "%Y-%m-%d %H:%M:%S.%3Q")
| eval ConvertedEnd=strptime(EndTime,"%Y-%m-%d %H:%M:%S,%3Q")
| eval ElapsedTime=ConvertedEnd-ConvertedStart

From common time variable formats, eval functions for date and time.

You may or may not need the eval for Elapsed time, it depends if it is properly seen as a time or as a string. Although, the idea is likely necessary because to do math on these, you'll want to convert them to unix Epoch times, which is what we do. So they're seconds past Jan 1, 1970. You'll have to convert them back to display them better (strftime and others, also able to be found from those above links).

0 Karma

GregZillgitt
Path Finder

|eval start=strptime("2017-02-03 09:51:54.595","%Y-%m-%d %H:%M:%S.%3N")
|eval end=strptime("2017-02-03 09:46:21,892","%Y-%m-%d %H:%M:%S,%3N")
|eval diffInSeconds=end-start

0 Karma
Get Updates on the Splunk Community!

What’s New & Next in Splunk SOAR

Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us on ...

Your Voice Matters! Help Us Shape the New Splunk Lantern Experience

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...