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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...