Splunk Search

Delta between two Date data fields

jasonhblackwell
Explorer

I am working on metrics for management and was wondering if it was able to compute the delta between two date data fields in an event? For example, one field is the start date and the other is the end date. Can Splunk figure out how many days lapsed in-between the start and end date?

Tags (1)

araitz
Splunk Employee
Splunk Employee

Assuming a standard date format (12-20-2010 08:20:25), you want to use the eval and convert search command:

...| convert timeformat='%m-%d-%Y %T' mktime(starttime) mktime(endtime) | eval duration=(endtime-starttime)/86400

This will tell you how many days (there are 86400 seconds in a day) elapsed between the starttime and the endtime. To do the arithmetic, we have to use the convert command to make standard date formats into epoch time (number of seconds since 1/1/1970).

kingbert_Thomas
New Member

This seems to be failing in my case

0 Karma

jasonhblackwell
Explorer

The data in my date fields is only 12/10/10. Will that be an issue?

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...