Splunk Search

How to compare close date with start date?

vishalduttauk
Path Finder

Hi there,

I am new to this kind of analysis within Splunk but i've been asked to create a filter on events where the closed date is before the start date.

This is the search I have created but can't get it working:

index=main sourcetype="CRA_Consumer_Txt_data" | eval close_date=strftime(strptime(close_date,"%d%m%Y"),"%d/%m/%Y") | eval start_date=strftime(strptime(start_date,"%d%m%Y"),"%d/%m/%Y") | search close_date < start_date | table start_date, close_date

 

This is an example of what even is shown when i run that search

 

start_date        close_date

30/04/2021        23/05/2021

Labels (3)
0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

Hi

You are quite close. When you are comparing dates it should always convert to epoch and then do the comparison.

index=main sourcetype="CRA_Consumer_Txt_data" 
| eval close_date_epoch = strptime(close_date,"%d%m%Y") 
| eval start_date_epoch = strptime(start_date,"%d%m%Y")
| where close_date_epoch < start_date_epoch
| eval close_date = strftime(close_date_epoch, "%d/%m/%Y"),
       start_date = strftime(start_date_epoch, "%d/%m/%Y")
| table start_date, close_date

View solution in original post

isoutamo
SplunkTrust
SplunkTrust

Hi

You are quite close. When you are comparing dates it should always convert to epoch and then do the comparison.

index=main sourcetype="CRA_Consumer_Txt_data" 
| eval close_date_epoch = strptime(close_date,"%d%m%Y") 
| eval start_date_epoch = strptime(start_date,"%d%m%Y")
| where close_date_epoch < start_date_epoch
| eval close_date = strftime(close_date_epoch, "%d/%m/%Y"),
       start_date = strftime(start_date_epoch, "%d/%m/%Y")
| table start_date, close_date

vishalduttauk
Path Finder

Thanks @isoutamo that has worked a treat and I now know to use epoch for this type of comparison! 😀

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

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