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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

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