Splunk Search

Splunk compare date strings by queries

h52huang
Path Finder

I want to compare date strings by splunk queries please. I have 2 dropdown inputs. StartDate and EndDate

I have below result set populated from a dropdown as 'StartDate'. If the user selects 2018-05-03, then my EndDate should only have 2018-05-07 and 2018-05-16 available for users to pick.
Date
2018-05-01
2018-05-03
2018-05-07
201805-16

How do I do the comparison logic within the same query please? Can Splunk compare dates alphabetically like Java strings ? Thank you.

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

In this case you can do a string comparison in order to test the dates. Here is a run-anywhere search (it sets up some data in the first three lines, then the last line is the one you want to look at) that can show you this capability:

| makeresults
| eval data="date1=2018-05-03 date2=2018-05-07"
| rex field=data "date1=(?P<date1>\S+)\s+date2=(?P<date2>\S+)"
| eval less=if(date1<date2,1,0)

The dates are compared as strings. The if function will allow you to do a comparison, then if true, take the first value, if false, take the second value.

0 Karma
Get Updates on the Splunk Community!

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

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