Splunk Search

Difference between two dates

kanalasreekanth
New Member

I have two fileds as below, now i would like to get difference date i.e Mydat-previousdate

Mydate | previousdate
2016-10-18T03:58:46 |152 day(s), 16 hour(s), 58 minute(s), 49 second(s)

Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Something like this should get you started.

... | rex field=previousdate "(?<days>\d+) day\(s\), (?<hrs>\d+) hour\(s\), (?<min>\d+) minute\(s\), (?<secs>\d+) second\(s\)" | fillnull value=0 | eval diff = strptime(Mydate,"%Y-%m-%dT%H:%M:%S") - (days * 86400) - (hrs * 3600) - (min * 60) - secs | eval diffDate = strftime(diff,"%Y-%m-%dT%H:%M:%S") | ...
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

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

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...