Splunk Search

Calculating duration from a number

whipstash
Engager

I am trying to find the duration for a time span. The "in" and "out" numbers are included in the data as type: number. I attempted:

in = 20240401183030

out = 20240401193030

| convert mktime(in) AS IN
| convert mktime(out) AS OUT
| eval Duration =OUT - IN

I have not been able to find a function that would directly convert number to time or if there is some multifunctional way to get the right duration between the two,

But this does not perform the correct time math. 

Labels (1)
0 Karma

whipstash
Engager

Thanks ITWhisperer! I did try the string conversion, but it did not work. This looks like it did the trick!

0 Karma

PickleRick
SplunkTrust
SplunkTrust

The "convert mktime()" could also be the way to go but you need to specify the time format with... the "timeformat=" option. Otherwise Splunk has to guess and usually guesses wrong.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval IN = strptime(in, "%Y%m%d%H%M%S")
| eval OUT = strptime(out, "%Y%m%d%H%M%S")
| eval Duration = tostring(OUT - IN,"duration")
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...