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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...