Splunk Search

How to set time to search

gurkiratsingh
Explorer

Hi am getting the earliest tie through a text box and I want to set the latest time automatically to (earliest+24h). Please help me how to do that. I do not want to use the time picker input.

<fieldset submitButton="false">
        <input type="text" token="time" searchWhenChanged="true">
          <label>Enter Date</label>
        </input>
      </fieldset>
    <search>
    <query>
index=abcd application="abcd"  earliest="$time$" |---------
</query>
<refresh>5m</refresh>
</search>

For example the user will enter the date as 03/15/2020:18:30:00 in the text field and I want the latest to be updated to this time+24h( 03/16/2020:18:30:00)

Tags (1)
0 Karma

vnravikumar
Champion

Hi

Check this

| makeresults 
| eval earliest="03/15/2020:18:30:00" 
| eval earliest_epoch = strptime(earliest,"%m/%d/%Y:%k:%M:%S"),latest_epoch=relative_time(earliest_epoch, "+d"), latest=strftime(latest_epoch,"%m/%d/%Y:%k:%M:%S")
0 Karma

gurkiratsingh
Explorer

Hi I tried what you mentioned. The latest variable is correctly extracting the next days time but when the search is happening it is taking (latest=now) instead of taking the value of latest.
earliest="03/23/2020:00:00:0" |eval earliest="03/23/2020:00:00:0"
| eval earliest_epoch = strptime(earliest,"%m/%d/%Y:%k:%M:%S"),latest_epoch=relative_time(earliest_epoch, "+d"), latest=strftime(latest_epoch,"%m/%d/%Y:%k:%M:%S")
|table earliest, latest

6 events (23/03/2020 00:00:00.000 to 25/03/2020 12:21:23.080)

latest earliest
03/24/2020: 0:00:00 03/23/2020:00:00:0
03/24/2020: 0:00:00 03/23/2020:00:00:0
03/24/2020: 0:00:00 03/23/2020:00:00:0
03/24/2020: 0:00:00 03/23/2020:00:00:0
03/24/2020: 0:00:00 03/23/2020:00:00:0
03/24/2020: 0:00:00 03/23/2020:00:00:0

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...