Splunk Search

How to calculate the difference between two dates?

marceldera
Explorer

I have 2 dates

first_found: 2022-08-23T21:08:54.808Z

last_fixed:2022-08-30T12:56:58.860Z

I am trying to calculate the difference in days between (first-found - last_fixed) and dump the result in a new field called "remediation_days"

 

Labels (1)
0 Karma

marceldera
Explorer

It works, however the results come back like this. 2419200.000000 even after i do the division.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Dates can only be compared/calculated in integer (epoch) form.

| eval remediation_days = (strptime(last_fixed, "%Y-%m-%dT%H:%M:%S.%3N%Z") - strptime(first_found, "%Y-%m-%dT%H:%M:%S.%3N%Z") / 86400)
---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Parens error on my part.

| eval remediation_days = (strptime(last_fixed, "%Y-%m-%dT%H:%M:%S.%3N%Z") - strptime(first_found, "%Y-%m-%dT%H:%M:%S.%3N%Z")) / 86400

There's also this alternative.

 

| eval remediation_secs = strptime(last_fixed, "%Y-%m-%dT%H:%M:%S.%3N%Z") - strptime(first_found, "%Y-%m-%dT%H:%M:%S.%3N%Z")
| eval remediation_days = round(remediation_secs / 86400, 2)

 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Accelerate Service Onboarding, Decomposition, Troubleshooting - and more with ITSI’s ...

Accelerate Service Onboarding, Decomposition, Troubleshooting - and more! Faster Time to ValueManaging and ...

New Release | Splunk Enterprise 9.3

Admins and Analyst can benefit from:  Seamlessly route data to your local file system to save on storage ...

2024 Splunk Career Impact Survey | Earn a $20 gift card for participating!

Hear ye, hear ye! The time has come again for Splunk's annual Career Impact Survey!  We need your help by ...