Splunk Search

How to find records based on input from user date?

agupta13
Engager

I have set of records where the data has time column in it.

Eg:

agupta13_0-1682724463553.png


Here I will have an input from user where user will enter the date in input box in any format (yyyy/mm/dd)
I want to find all records that are greater than the time entered by user.

 

Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

The problem is the "any" in any format.  Does this mean the user choses any format they wish, or does this mean that you dictate any format for your user?  If it is a free text input, while it is possible to parse multiple common date format, it is impossible to be exhaustive.

If you can dictate, say "yyyy/mm/dd" as you exemplified, it will be simple.  Say, your input token is $date_tok$.

| where _time > strptime($date_tok$, "%Y/%m/%d")
Tags (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

+1 on the date format - the simplest argument against "any" format is eu vs. us date - does 1/3/23 mean Jan 3rd or March 1st?

Also if you can (and in your case the timestamp seems to be contained in the _time field) you should filter by time as early as possible (time is the most efficient filter) so why not just use time picker to limit your search range?

0 Karma
Get Updates on the Splunk Community!

Pro Tips for First-Time .conf Attendees: Advice from SplunkTrust

Heading to your first .Conf? You’re in for an unforgettable ride — learning, networking, swag collecting, ...

Raise Your Skills at the .conf25 Builder Bar: Your Splunk Developer Destination

Calling all Splunk developers, custom SPL builders, dashboarders, and Splunkbase app creators – the Builder ...

Hunt Smarter, Not Harder: Discover New SPL “Recipes” in Our Threat Hunting Webinar

Are you ready to take your threat hunting skills to the next level? As Splunk community members, you know the ...