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 Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...