Splunk Search

Search to find where one date field starts before another

vishalduttauk
Communicator

Hi there,

I have a search where I want to see where one date field is the same or starts before another but my search results only shows me events where both dates are the same, can you help?

I am trying to find events which contains an end date that is before the created date.

The data isn't create so a typical date entry would be 12112022

index=UAT sourcetype="Test_Txt_data"
| eval end_date_epoch = strptime(end_date,"%d%m%Y")
| eval created_date_epoch = strptime(created_date,"%d%m%Y")
| where end_date_epoch <= created_date_epoch
| eval end_date = strftime(end_date_epoch, "%d/%m/%Y"),
created_date = strftime(created_date_epoch, "%d/%m/%Y")
| table proposal, created_date, end_date

Labels (4)
0 Karma
1 Solution

rrovers
Contributor

I don't know what's exactly in your index but this works:

|makeresults 
|eval end_date="10112022"
| eval created_date="12112022"
| eval end_date_epoch = strptime(end_date,"%d%m%Y")
| eval created_date_epoch = strptime(created_date,"%d%m%Y")
| where end_date_epoch <= created_date_epoch
| eval end_date = strftime(end_date_epoch, "%d/%m/%Y")
| eval created_date = strftime(created_date_epoch, "%d/%m/%Y")
| table proposal, created_date, end_date

If this doesn't solve your problem please give some more information

View solution in original post

rrovers
Contributor

I don't know what's exactly in your index but this works:

|makeresults 
|eval end_date="10112022"
| eval created_date="12112022"
| eval end_date_epoch = strptime(end_date,"%d%m%Y")
| eval created_date_epoch = strptime(created_date,"%d%m%Y")
| where end_date_epoch <= created_date_epoch
| eval end_date = strftime(end_date_epoch, "%d/%m/%Y")
| eval created_date = strftime(created_date_epoch, "%d/%m/%Y")
| table proposal, created_date, end_date

If this doesn't solve your problem please give some more information

vishalduttauk
Communicator

Thanks @rrovers that has worked a treat 🙂

Tags (1)
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...