Splunk Search

Splunk date comparison

mcamilleri
Path Finder

I need to be able to search for log entries with a specific start date, which has nothing to do with _time. The format is, for example, Start_Date: 08/26/2013 4:30 PM.

I need to add a condition in my search to specify the date, but not the time. I tried strptime and strftime unsuccessfully.

For example, I tried converting start date to a string (without time) and compare it to another string:

"08/26/2013"=strftime(Start_Date, "%d/%m/%Y")

This didn't work either:

 "08/26/2013"=strftime(strptime(Start_Date "%d/%m/%Y %I:%M %p"), "%d/%m/%Y")

Any ideas how to solve this?

1 Solution

kristian_kolb
Ultra Champion

If Start_Date is an extracted field you can just add it to the search in a key=value format, e.g;

host=blah sourcetype=bleh Start_Date=08/26/2013*

If it is not an extracted field, and you do not wish it to be, you can extract within the search first;

host=blah sourcetype=bleh | rex "Start_Date:\s(?<Start_Date>\S+)" | search Start_Date=06/26/2013*

Your use of strftime/strptime is not correct. Those two are functions of eval.

Hope this helps,

K

View solution in original post

0 Karma

rturk
Builder

If you want to use comparison operators instead of just making sure the string is equal to "08/26/2013 4:30 PM" (e.g. "return all events that have a start date after 09/24/2012"), you will need to convert the time into epoch seconds.

<base search> | eval start-epoch=strptime(Start_Date, "%m/%d/%Y %I:%M %p")

This will give you a new field start-epoch that may be used for comparison purposes.

NOTE: This assumes you have a field called Start_Date. If you do not, you will need to extract the date similarly to how kristian.kolb did in the other answer provided.

Hope this helps! 🙂

References:

kristian_kolb
Ultra Champion

If Start_Date is an extracted field you can just add it to the search in a key=value format, e.g;

host=blah sourcetype=bleh Start_Date=08/26/2013*

If it is not an extracted field, and you do not wish it to be, you can extract within the search first;

host=blah sourcetype=bleh | rex "Start_Date:\s(?<Start_Date>\S+)" | search Start_Date=06/26/2013*

Your use of strftime/strptime is not correct. Those two are functions of eval.

Hope this helps,

K

0 Karma

mcamilleri
Path Finder

Thanks! Start_Date=08/26/2013* works perfectly.

0 Karma

royimad
Builder

Use
search sourcetype="comparison" | eval existing_date=functions()
instead of comparing between 2 different dates of your search solve
evaluation function instead of equal sign, 2 different dates can not be equal try to use your existing dates to be compatible with your start_date format

Hope this will help.

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

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