Splunk Search

Search to find where one date field starts before another

vishalduttauk
Path Finder

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
Communicator

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
Communicator

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
Path Finder

Thanks @rrovers that has worked a treat 🙂

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...