Splunk Search

How can i calculate datetime Difference between two datetime values.

abhishekgupta61
Engager

Begin date - 2018-05-02 22:00:23.235371
End Date - 2018-05-02 22:01:33.815546

Expected Result should be - 70

Tags (1)
0 Karma

xpac
SplunkTrust
SplunkTrust

Hey, try this:

| makeresults
| eval begin="2018-05-02 22:00:23.235371"
| eval end="2018-05-02 22:01:33.815546"
| eval begin_epoch=strptime(begin, "%Y-%m-%d %H:%M:%S")
| eval end_epoch=strptime(end, "%Y-%m-%d %H:%M:%S")
| eval diff=end_epoch-begin_epoch

The field diff will then contain the difference between the two. I left out the milliseconds on purpose, because you said you expected "70" as a result.

Hope that helps - if it does I'd be happy if you would upvote/accept this answer, so others could profit from it. 🙂

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...