Splunk Search

Subtract two timestamps in one event

jscottmiller
New Member

Hopefully this is a simple question, but I haven't found a way to do so using either the convert or eval commands. Basically, I have two timestamps in my events, a start time and an end time. I want to compute a duration (preferably in seconds) by subtracting the two. Is there a simple way to do this?

Tags (1)
0 Karma

JohnB
Explorer

Add something like this:

| eval TotalTime = strptime(end_time, "%Y-%m-%dT%H:%M:%S%z") - strptime(start_time, "%Y-%m-%dT%H:%M:%S%z")

(Assuming your date format is in that type of time stamp).

gkanapathy
Splunk Employee
Splunk Employee

You can use either convert mktime() or the eval strptime() functions to convert both timestamps to epoch time, then just subtract one from the other.

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