Splunk Search

Want to fetch data of 3 weeks, before any date and time entered

intelsubham
Explorer

Working on development of a form based dashboard where user will enter a date, and I want to fetch 3 weeks data before that date.so what should be the earliest and latest accordingly?

Example: suppose user entered 7/14/2014:00:00:00, data should be fetched for 3-weeks before that date.

Tags (3)
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

You could calculate the earliest_time in an eval-based macro like this:

index=foo sourcetype=bar earliest_time=`three_weeks_before($date$)` latest_time="$date$" | ...

With the macro three_weeks_before(1) defined like this:

relative_time(strptime("$date$", "%m/%d/%Y:%H:%M:%S"), "-3w")

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

You could calculate the earliest_time in an eval-based macro like this:

index=foo sourcetype=bar earliest_time=`three_weeks_before($date$)` latest_time="$date$" | ...

With the macro three_weeks_before(1) defined like this:

relative_time(strptime("$date$", "%m/%d/%Y:%H:%M:%S"), "-3w")
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...