Splunk Search

How to find the number of days between a certain date field and today?

nspatel
Explorer

Hi Everyone,

I have a field called 'ddate'. This field is setup in the 'yyyy-MM-dd hh:mm:ss' format. I would like to know how many days ago that date was from today.

Data looks like this:
ddate="2014-08-18 09:07:47"

I need this in the end to be a number. Any idea? Thanks!

Tags (2)
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Something like this?

... | eval ddate_epoch = strptime(ddate, "%Y-%m-%d %H:%M:%S") | eval diff_seconds = now() - ddate_epoch | eval diff_days = diff_seconds / 86400

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Something like this?

... | eval ddate_epoch = strptime(ddate, "%Y-%m-%d %H:%M:%S") | eval diff_seconds = now() - ddate_epoch | eval diff_days = diff_seconds / 86400

nspatel
Explorer

Ah I see what I was doing wrong now! Thank you so much Martin!!!!!!!

0 Karma
Get Updates on the Splunk Community!

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 ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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