Splunk Search

How to get the difference (In whole days) between two fields within the same event

Matthew
Engager

Hi Guys, 

Wondering if you can help me out with the following. Within a single event I have to fields: 

1) expiry_date

2) delivery_date

I would create a new variable giving me the difference in days between the delivery date and the expiry date for each order. 

For example 

expiry_date=2021-05-25T00:00:00Z

delivery_date=2021-04-27T19:00:44Z

Should give a result of 28days. 

Hope you can help! Thanks in advance. 

Labels (2)
0 Karma
1 Solution

harsmarvania57
Ultra Champion

Here you go

<your_query>
| eval diff=tostring(strptime(expiry_date, "%Y-%m-%dT%H:%M:%S%Z")-strptime(delivery_date, "%Y-%m-%dT%H:%M:%S%Z"), "duration")

 

Sample query which I ran

| makeresults 
| eval expiry_date="2021-05-25T00:00:00Z", delivery_date="2021-04-27T19:00:44Z"
| eval diff=tostring(strptime(expiry_date, "%Y-%m-%dT%H:%M:%S%Z")-strptime(delivery_date, "%Y-%m-%dT%H:%M:%S%Z"), "duration")

View solution in original post

harsmarvania57
Ultra Champion

Here you go

<your_query>
| eval diff=tostring(strptime(expiry_date, "%Y-%m-%dT%H:%M:%S%Z")-strptime(delivery_date, "%Y-%m-%dT%H:%M:%S%Z"), "duration")

 

Sample query which I ran

| makeresults 
| eval expiry_date="2021-05-25T00:00:00Z", delivery_date="2021-04-27T19:00:44Z"
| eval diff=tostring(strptime(expiry_date, "%Y-%m-%dT%H:%M:%S%Z")-strptime(delivery_date, "%Y-%m-%dT%H:%M:%S%Z"), "duration")

Matthew
Engager

Hi harsmarvania57, 

Worked like a charm. Thank you!

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...