Splunk Search

subtracting 2 timestamps and then evaluating if that result is longer than 1 hour

samnew4598
Explorer

I have two timestamps that are in this format within my log events:

start: 2005-07-05T04:28:34.453494Z

end: 2005-07-05T05:28:39.462681Z

I would like to subtract the timestamps then evaluate them to see if the result is greater or equal to 1 hour and include that event in my query results

Extra:

if so how long?

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex "start: (?<start>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| rex "end: (?<end>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| eval start=strptime(start,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval end=strptime(end,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval diff=end-start
| where diff>=(60*60)
| fieldformat diff=tostring(diff,"duration")

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| rex "start: (?<start>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| rex "end: (?<end>\d{4}\-\d\d\-\d\dT\d\d:\d\d:\d\d\.\d+Z)"
| eval start=strptime(start,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval end=strptime(end,"%Y-%m-%dT%H:%M:%S.%6QZ")
| eval diff=end-start
| where diff>=(60*60)
| fieldformat diff=tostring(diff,"duration")

samnew4598
Explorer

This works great! If you have time can you explain it a bit, I don't know why we need to use "rex" to extract the time? I get the rest of the query as that was one of my initial tries but without the rex. Thanks!

 

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

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